Application path

  • Thread starter Thread starter Marc Robitaille
  • Start date Start date
M

Marc Robitaille

hello,

How can I have the path of my web application from the global.asax.vb ? I
need the path because I have to create an xml file when the application
start.

thank you
Marc R.
 
How can I have the path of my web application from the global.asax.vb ? I
need the path because I have to create an xml file when the application
start.

Have a look at Server.MapPath
 
Here is some sample code I use for setting up a directory for my XML
file I/O. It's in C#, but it should give you a good idea of the overall
structure and function calls.

<snippet>


// Logging and Configuration constants
private const string EVT_PROGRAMNAME = "TekGuard
WebMail";
private const string DIR_PATHPUBLIC =
"TGWebMail\\Pub\\";

// Internal Constants
internal const string APP_PATHPUBLIC = "PathPublic";
internal const string SES_USERNAME = "UserName";
internal const string SES_PATHUSER = "PathUser";


protected void Application_Start(Object sender, EventArgs e)
{
// Create the application level data path object
string PathServer = Server.MapPath("~/");

// Get the full path of the public directory
// m_PublicPath = PathServer + DIR_PATHPUBLIC; // Root of
virtual web
m_PublicPath = Directory.GetDirectoryRoot(PathServer) +
DIR_PATHPUBLIC;

// Do I have directory storage permission, etc?
try
{
if (!Directory.Exists(m_PublicPath))
Directory.CreateDirectory(m_PublicPath);

// Create the application level data path object; Store the
path for page use
Application.Add(APP_PATHPUBLIC, PathPublic);
}
catch(Exception ex)
{
// m_LogTools.WriteWinAppEvent ("Error setting bootstrap
initialization settings (see log file for details), " + ex.Message,
EventLogEntryType.Error);
Response.Write (EVT_PROGRAMNAME + ": " + ex.Message);
throw new ApplicationException(EVT_PROGRAMNAME + ": " +
ex.Message);
}
}



internal static bool
UserInit(System.Web.SessionState.HttpSessionState Session, object
UserName, object ServerName)
{
// Create the fully qualified directory path for this user
string PathUser = m_PublicPath + ServerName.ToString().ToLower()
+ "\\" + UserName.ToString().ToLower() + "\\";

// Do I have directory storage permission, etc?
try
{
if (!Directory.Exists(PathUser))
Directory.CreateDirectory(PathUser);
Session.Add(SES_PATHUSER, PathUser);
return (true);
}
catch
{
}
return (false);
}

private void Page_Load(object sender, System.EventArgs e)
{
// Load default identity data from XML
path = Session[Global.SES_PATHUSER].ToString()
...
...
...
}

</snippet>


www.VoiceInfo.com - <a href="http://www.VoiceInfo.com">
Virtual Office, Automated Phone Assistant, Web Access </a><br>

www.TekGuard.com - <a href="http://www.TekGuard.com">
Free Mail Server, Outlook PlugIn, WebMail, Source Code </a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top