.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How do I find the file path from a namespace.class name?

Posted By:      Posted Date: August 26, 2010    Points: 0   Category :ASP.Net

I'm programatically looking ito a .aspx file and getting the file class name declared in its CodeBehind. For example, when analyzing myFile.aspx I read in its Page Directive and found its CodeBehind equals "myApplication\myPage.aspx.vb". Then I use the code below:


Dim Assm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("myApplication\bin\myApplication.dll")
Dim ClassType As Type = Assm.GetType("myApplication\myPage.aspx.vb")
' myBaseType = "myApplication.Forms.BasePage"
Dim myBaseType As System.Type = ClassType.BaseType


Now I want to read the BaseFile (class = myApplication.Forms.BasePage). However, to read in this file, I need I need to get its full path instead of its namespace.class hiearchy. In this case, the BasePage is wrapped in a different namespace declaration thus I cannot just change the '.' to '\' in order to get the path.

How can I get the path of BasePage so I can read it? Thank you - Frank

View Complete Post

More Related Resource Links

How to get a file path in a class library used by asp.net

 Hello,   I have an asp.net application which employs a class project to process xml files. I have an xsd file within the class project. To load the xsd file, I am not sure which path I should use. The following code snippet loads the xsd, and reads the xsd using the StreamReader. I am not sure how to set the value for xsdPath variable.// 2- Read Schema file content StreamReader SR = new StreamReader(xsdPath); // 3- Create a new instance of XmlSchema object XmlSchema Schema = new XmlSchema(); // 4- Set Schema object by calling XmlSchema.Read() method Schema = XmlSchema.Read(SR, new ValidationEventHandler(ReaderSettings_ValidationEventHandler)); Thanks  

Upload image to database - couldn't find file path

I'm trying to display images in a GridView (yes, still this...). [edit] Before I can come to that I have to upload some images to the database.I've followed this tutorial for the "upload image to database" code (this worked fine for uploading images, but I don't know if the images were converted to byte):http://aspsnippets.com/Articles/Save-Files-to-SQL-Server-Database-using-FileUpload-Control.aspxand I've followed this tutorial for the "display images in gridview" code (and "retrieve file" from the tutorial below).http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspxIt doesn't quite work, the GridView shows but without imagesNow I'm trying to change the "save file" code according to this tutorial:http://aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASP.Net.aspxbut I don't understand everything in it. When I try to upload an image I get an error on this line:FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); //couldn't find file (path to image I tried to upload) What should I do about it?

Using loginName to find ADInfo from an outside class



I wrote a class to pull adinfo and for the life of me I can't seem to figure

out why it says "Invalid Login Name" no matter what I type in. If I leave

it blank it seems to work properly but it doesn't seem to be actually searching

the AD. I'll drop the whole class here, it's being initiated by a button click

on an outside form.


Thanks in Advance for any help Offered,



Imports System.DirectoryServices
Imports Microsoft.VisualBasic
Imports System.String
Imports System.Collections
Imports System.Security.Principal
Imports System.Security.Permissions

Namespace LoginButton
    Public Class LoginButton

        'Class Variables
        Dim UserID As String = Nothing
        Dim DomainDN As String = ConfigurationManager.AppSettings("myConnectionString")
        Dim ADEntry As DirectoryEntry = New DirectoryEntry(DomainDN)
        Dim objSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
        Dim oResults As DirectoryServices.SearchResultCollection
        Dim oResult As DirectoryServices.SearchResult
        Dim RetArray As New Hashtable
        Dim page As Page = DirectCast(HttpContext.Current.Handler, Page)
        Dim TextLogin = DirectCast(page.FindControl("

Make sure that the class defined in this code file matches the 'inherits' attribute, and that it e


Here is the page directive for the page that throws the error:

@ Page language="c#" Inherits="University.AspNet.Index" CodeFile="Index.aspx.cs" %>

The code behind file Index.aspx.cs starts like this:

using University.Framework.UI;

namespace University.AspNet

public partial class Index : University.Framework.UI.HomePage

The code behind is extending this HomePage class, which is in turn an extenstion of another class University.Framework.UI.Page, which extends the System.Web.UI.Page class.

Am I misusing the I

Cant find vsi file for CSS Friendly Control Adapters


Hi guys

This is driving me crazy... I cant find the .vsi file for installing the CSS Friendly Control Adapters Project. Does anyone know where I can get this?

The following link: http://www.asp.net/cssadapters/ only leads to the CodePlex wiki where I can download the dll and a partial solution. Essentially, I'm looking for the source code to implement the Menu adapter.

Any help is much appreciated!

Class Templates: Bring the Power of Templates to Your .NET Applications with the CodeDOM Namespace


In the .NET Framework, the CodeDOM object model can represent code in a variety of languages. This article examines how source code templates written with the Framework's System.CodeDom and System.CodeDom.Compiler namespaces allow developers to create reusable boilerplate source code that can be shared between projects. Components designed via templates improve productivity and shorten development time.Here C++-style classes and templates are simulated and code is generated in multiple languages through the creation of CodeDOM object graphs. Compiling object graphs and formatting output code are also explained.

Adam J. Steinert

MSDN Magazine February 2003

File Attachments from info-path forms to Sharepoint document library


Hi Experts,

How to upload file attachements from info-path forms to Sharepoint document library?

I need to add attachement from local-PC/Any User to Sharepoint Document Library.


Any help please?? Appreciated




Error: Do you want to save this file, or find a program online to open it?



I am relatively new to MVC , i am getting the following error when i try to browse to a page in which i have used usercontrol and within the usercontrol i have a simple grid.

Error: Do you want to save this file, or find a program online to open it?

I am returning the data from the controller like this

 var jsonData = new
                    total = 1,
                    page = 1,
                    records = myRequests.Count,
                    rows = new[]{myRequests.ToArray()                 

How to set WebService NameSpace in web.config file?


I am trying to put the namespace value as a key in web.config file, so that when I deploy this on production, I just have to change the namespace key in the config file only, not on all of my webservice cs files. But When I try to browse this webservice after changing this code I get compilation error.


    <add key="NameSpace" value="http://csi-dev-deep/"/>

MyWebService.cs (this code works)

[WebService(Namespace = "http://csi-dev-deep/")]

MyWebService.cs code changed to the following gives compilation error.
[WebService(Namespace = ConfigurationManager.AppSettings["NameSpace"].ToString())]

Compiler Error Message: CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

Your help is highly appreciated.

Thank you.

Could not find a part of the path ... Occuring even if it's not required

I have a windows application which will be installed on a client PC. However, when the user tries to run the app, an error is thrown up.   Could not find a part of the path "C:\Documents and Settings\$username$\Application Data\$appName folder$\sample_log.txt   I looked in the code..but could not find any reference to the file named sample_log.txt . There's no code that creates this file. Although, I know, we had in the past created this file for testing purposes and then deleted the code.   Thank You    

Acces the file upload path

how can i acces the file upload text. I mean if i choose a file , then the file path comes in file upload e.g. c:/data/fil1.txt.All i want to acces this full path and show in a label.

File Stream Class

 I am trying to write to a text file while protecting it from concurrent access. What is the advantage of fileStream.lock ? (when I created a filestream in the code below, the file seemed to be protected from other processes using it). I am not sure if I need to use filestream.lock below. Please advise ..            Public Shared Sub writeToLogFile(ByVal logMessage As String)         Try             Dim strLogMessage As String = String.Empty             Dim strLogFile As String = System.Web.HttpContext.Current.Server.MapPath("~/Log.txt")             Dim swLog As StreamWriter             strLogMessage =  DateTime.Now.ToLongTimeString().ToString() & " ==> " & logMessage             Dim fileStream As New FileStream(strLogFile, FileMode.Append)            ' Lock all of the file after creating the filestream object             fileStream.Lock(0, fileStream.Length)      &nb

Access to path xxx denied when uploading a file using c#

Hi I have a file upload app written in c#. The app runs on IIS on a Windows 2003 Server OS. I want the app to upload the file onto the server (The app and the server are on the same machine). This code has been working fine for a long time running on Windows Server 2000, and Windows XP Professional. Now when I moved onto Windows Server 2003, it stopped working. I have given ASPNET account full access to the folder on the server, and it still gives this error. Is this a bug in 2003, and can anybody assist me? Thanks Shane

Method/Way to know whether a input path of FilesSystem contains any Child file/folder or not

Hi,I am looking for a Method/Way to know whether a input path of FilesSystem contains any Child file/folder or not. To know it currently I am using "Directory.GetFileSystemEntries(Path).Count" and checking if count > 0 then returning True else False. For this first method calculates all the files and folder and then return status to me but I want to exit out as soon as my method gets first element(file/folder) in specified path. Because above method is timing out when my input path contains more than 1 million files. I just need to check whether input folder path contains any child file/folder or not. I have tried to use Win32 API also but on ther server it is crashing so I donot want to use that solution. In .NET any method or way is present to know it. Please suggest me.

Working with System.IO.Path static class

Hello everyone. Today, I was exploring the System.IO namespace in .NET 4.0 on an ASP.NET web application where I came to few changes, comparing with the previous versions of .NET, related to the System.IO.Path static class. The Path class contains the same method names in .NET 2.0, 3.5 as well as 4.0, only (in .NET 4.0) new overloads are added to System.IO.Path.Combine() method. In the following blog post, I will show the usage of few methods belonging to the System.IO.Path static class, as well as, the changes in Combine() method added in .NET 4.0. Besides the first method that is available in the previous versions for combining two string paths, now in .NET 4.0 you can combine unlimited strings to the path. Note: For testing purpose, on your web application root, create folders with name Files, Files/SubFolder, Files/SubSubFolder and add three text files: text1.txt (in Files), text2.txt (in Files/SubFolder), text3.txt (in Files/SubFolder/SubSubFolder).   Here are few examples:             string path1 = System.IO.Path.Combine(Server.MapPath("Files"), "text1.txt"); //this will give the path to %WEBAPP_ROOT%/Files/text1.text -             string path2 = System.IO.Path.Combine(Server.MapPath("Files"), "SubFolder", "text2.txt"); //this will give

Download a file from web and save dialog box for path

Hi I need to download a exe file from a web site. I need to prompt a savedialog box for the user to select a path to save it. This the code i have. How can i show a save dialog box here?         Private Sub downloadfile()         Dim client As New Net.WebClient         client.DownloadFile("www.mysite.com/Information/Myexe.exe", "Sr.exe")     End Sub Thanks

Access ViewState in Class File

The article Access ViewState in Class File was added by bhaarat on Wednesday, September 01, 2010.Many times we might need to access Viewstates in classfilewhich is not availablethis is a way to access the Viewstte in Class fileon code Behind%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend