C # webform file access and get application current path

Source: Internet
Author: User
Tags httpcontext

WINFOM get the application's current path
System.diagnostics.process.getcurrentprocess (). Mainmodule.filename;
Gets the full path of the main module that is associated with the currently active process, including the filename (process name), for the new process component.
Return e:c# Learn get current path get current path Bindebug get current path. exe system.appdomain.currentdomain.setupinformation.applicationbase;
Gets and sets the name of the directory that contains the application.
Return e:c# Learn get current path get current path bindebug
System.windows.forms.application.startuppath;
Gets the path of the executable file that started the application, excluding the name of the executable file.
Return e:c# Learn get current path get current path bindebug
System.windows.forms.application.executablepath;
Gets the path to the executable that started the application, including the name of the executable file.
Return e:c# Learn get current path get current path Bindebug get current path. exe system.io.directory.getcurrentdirectory ();
Gets the current working directory of the application (unreliable).
Return e:c# Learn get current path get current path bindebug
This.gettype (). assembly.location;
Gets the full path of the current process, including the filename (process name).
Sorry static method is not available
Return e:c# Learn get current path get current path Bindebug get current path. exe

String path = ""; if (system.environment.currentdirectory = = appdomain.currentdomain.basedirectory)//windows application is equal to {path =  Appdomain.currentdomain.basedirectory;   else {path = appdomain.currentdomain.basedirectory + ' bin '; }

C # webform File access

String[] Getdirectoryfiles (string dirvpath, String pattern)
{
String dirvpathrooted = String.Concat (
Httpcontext.current.request.applicationpath.tolower (),
Dirvpath);
String dirpath = Httpcontext.current.server.mappath (dirvpathrooted);

string[] files = directory.getfiles (Dirpath, pattern, searchoption.alldirectories);
String[] includes = new String[files.length];
for (int i = 0; i < files.length; i++)
{
Includes[i] = Files[i]
. replace (Dirpath, Dirvpath)//Replace physical root by virtual root
. replace (', '/');
}
return includes;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.