当前位置: 首页>>代码示例>>C#>>正文


C# HttpServerUtility.MapPath方法代码示例

本文整理汇总了C#中System.Web.HttpServerUtility.MapPath方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServerUtility.MapPath方法的具体用法?C# HttpServerUtility.MapPath怎么用?C# HttpServerUtility.MapPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpServerUtility的用法示例。


在下文中一共展示了HttpServerUtility.MapPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

        public static void Init(HttpServerUtility server)
        {
            string configPath = Path.Combine(PARENT_CONFIG_PATH, DefaultConfigName);
            DefaultConfigPath = server.MapPath(configPath);

            //By default if there's no config let's create a sqlite db.
            string defaultConfigPath = DefaultConfigPath;

            string sqlitePath = Path.Combine(DATA_FOLDER, DEFAULT_SQLITE_NAME);
            sqlitePath = server.MapPath(sqlitePath);

            if (!File.Exists(defaultConfigPath))
            {
                ConfigFile file = new ConfigFile(defaultConfigPath);

                file.Set(DbConstants.KEY_DB_TYPE, DbConstants.DB_TYPE_SQLITE);
                file.Set(DbConstants.KEY_FILE_NAME, sqlitePath);
                file.Save();

                CurrentConfigFile = file;
            }
            else
            {
                CurrentConfigFile = new ConfigFile(defaultConfigPath);
                CurrentConfigFile.Load();
            }

            CurrentDbProvider = DbProviderFactory.Create(CurrentConfigFile);
        }
开发者ID:nzgeek,项目名称:WebGoat.NET,代码行数:29,代码来源:Settings.cs

示例2: Save

        public static string Save(HttpServerUtility server, Stream stream, string fileName) {

            string fileExtension = Path.GetExtension(fileName);
            string relativePath = $"{RootFileName}/{Unknow}/";
            string savePath = server.MapPath($"~/{relativePath}");

            if (!string.IsNullOrEmpty(fileExtension)) {
                //去掉extension的.
                relativePath = $"{RootFileName}/{fileExtension.Substring(1)}/";
                savePath = server.MapPath($"~/{relativePath}/");
            }

            if (!Directory.Exists(savePath)) {
                Directory.CreateDirectory(savePath);
            }

            string newFileName = Guid.NewGuid().ToString("N") + fileExtension;
            string saveFile = Path.Combine(savePath, newFileName);
            bool success = FileHelper.WriteFile(stream, saveFile);
            string retFile = "";
            if (success) {
                retFile = $"{Address}{relativePath}{newFileName}";
            }

            return retFile;
        }
开发者ID:TheTypoMaster,项目名称:DotNet.Mix,代码行数:26,代码来源:FileStore.cs

示例3: WriteLog

        const string Token = "youotech"; //定义一个局部变量不可以被修改,这里定义的变量要与接口配置信息中填写的Token一致

        #endregion Fields

        #region Methods

        /// <summary>
        /// 写日志(用于跟踪),可以将想打印出的内容计入一个文本文件里面,便于测试
        /// </summary>
        public static void WriteLog(string strMemo, HttpServerUtility server)
        {
            string filename = server.MapPath("/log/log.txt");//在网站项目中建立一个文件夹命名logs(然后在文件夹中随便建立一个web页面文件,避免网站在发布到服务器之后看不到预定文件)
            if (!Directory.Exists(server.MapPath("//log//")))
                Directory.CreateDirectory("//log//");
            StreamWriter sr = null;
            try
            {
                if (!File.Exists(filename))
                {
                    sr = File.CreateText(filename);
                }
                else
                {
                    sr = File.AppendText(filename);
                }
                sr.WriteLine(strMemo);
            }
            catch
            {
            }
            finally
            {
                if (sr != null)
                    sr.Close();
            }
        }
开发者ID:mildrock,项目名称:wechat,代码行数:36,代码来源:Default.aspx.cs

示例4: Register

 public static void Register(HttpServerUtility server)
 {
     ConstantManager.LogPath = server.MapPath("~/Areas/Admin/LogFiles/");
     ConstantManager.ConfigPath = server.MapPath("~/Areas/Admin/AdminConfig.xml");
     ConstantManager.SavedPath = server.MapPath("~/Areas/Admin/SavedPages");
     ConstantManager.TrainingFilePath = server.MapPath("~/UploadedExcelFiles/ProductName.txt");
     ConstantManager.DistanceFilePath = server.MapPath("~/CalculateMarketDistance.xml");
     ConstantManager.IsParserRunning = false;
 }
开发者ID:dimparis,项目名称:smart-buy,代码行数:9,代码来源:ConstantConfig.cs

示例5: DownloadImage

        public static string DownloadImage(string url,string mid, HttpServerUtility obj)
        {
            byte[] data;
            string path="";
            using (WebClient client = new WebClient())
            {
                data = client.DownloadData(url);
            }
            if (data == null)
                return null;
            path = "Images/"+mid+"_"+ url.GetHashCode() + ".jpg";
                if (!File.Exists(obj.MapPath(path)))
                    File.WriteAllBytes(obj.MapPath(path), data);

            return path;
        }
开发者ID:Walliee,项目名称:PicBook,代码行数:16,代码来源:Utilities.cs

示例6: CreateTemplateFileIfNotExists

        /// <summary>
        /// Creates a template file if it does not already exists, and uses a default text to insert. Returns the new path
        /// </summary>
        public string CreateTemplateFileIfNotExists(string name, string type, string location, HttpServerUtility server, string contents = "")
        {
            if (type == RazorC)
            {
                if (!name.StartsWith("_"))
                    name = "_" + name;
                if (Path.GetExtension(name) != ".cshtml")
                    name += ".cshtml";
            }
            else if (type == RazorVb)
            {
                if (!name.StartsWith("_"))
                    name = "_" + name;
                if (Path.GetExtension(name) != ".vbhtml")
                    name += ".vbhtml";
            }
            else if (type == TokenReplace)
            {
                if (Path.GetExtension(name) != ".html")
                    name += ".html";
            }

            var templatePath = Regex.Replace(name, @"[?:\/*""<>|]", "");
            var absolutePath = server.MapPath(Path.Combine(GetTemplatePathRoot(location, App), templatePath));

            if (!File.Exists(absolutePath))
            {
                var stream = new StreamWriter(File.Create(absolutePath));
                stream.Write(contents);
                stream.Flush();
                stream.Close();
            }

            return templatePath;
        }
开发者ID:2sic,项目名称:2sxc,代码行数:38,代码来源:TemplateManager.cs

示例7: AbsoluteDirectoryPathList

        /// <summary>
        /// First converts tildeDirectoryPath to lowercase.
        /// 
        /// Then uses the server to convert tildeDirectoryPath
        /// to an absolute base directory path.
        /// 
        /// Then produces the list of absolute directory paths
        /// whose tree roots itself at this base path.
        /// 
        /// If there is an error then may return an empty list.
        /// </summary>
        public static List<string> AbsoluteDirectoryPathList(HttpServerUtility server, string tildeDirectoryPath)
        {
            List<string> list = new List<string>();

            string path = tildeDirectoryPath.ToLower();

            if (StringTools.IsTrivial(path))
                goto returnstatement;

            if (path[0] != '~')
                goto returnstatement;

            int n = path.Length;

            if (path[n - 1] != '/')
                path = path + '/';

            if (!SourceTools.OKtoServe(path, true))
                goto returnstatement;

            try
            {
                string directoryPath = server.MapPath(path);
                AbsoluteDirectoryPathListHelper(list, directoryPath);
            }
            catch { }

            returnstatement:

            return list;
        }
开发者ID:rewanth21,项目名称:freetime,代码行数:42,代码来源:FileListTools.cs

示例8: Start

    public static void Start(HttpServerUtility server)
    {
      DeNSo.Configuration.BasePath = server.MapPath("~/App_Data");
      DeNSo.Configuration.EnableJournaling = true;

      Session.DefaultDataBase = "densodb_webapp";
      Session.Start();
    }
开发者ID:dronab,项目名称:DensoDB,代码行数:8,代码来源:DensoConfig.cs

示例9: LoadDiskCache

        internal static void LoadDiskCache(HttpServerUtility server)
        {
            var cache = server.MapPath("~/App_Data/api_start2.json");
            if(!File.Exists(cache)) return;

            start2Content = File.ReadAllText(cache);
            start2Timestamp = (long)((File.GetLastWriteTimeUtc(cache) - Utils.UnixTimestamp.Epoch.UtcDateTime).TotalMilliseconds);
        }
开发者ID:trhyfgh,项目名称:OoiSharp,代码行数:8,代码来源:KcsApiStart2Handler.cs

示例10: getDataSetFromExcel

        public static DataSet getDataSetFromExcel(FileUpload FileUpload1, HttpServerUtility Server)
        {
            if (FileUpload1.HasFile)
            {
                string fileName = Path.GetFileName(FileUpload1.FileName);
                string filePath = Server.MapPath("~/Excel/" + fileName);
                string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName);

                try
                {

                    MemoryStream stream = new MemoryStream(FileUpload1.FileBytes);
                    IExcelDataReader excelReader;

                    if (fileExtension == ".xls")
                    {
                        excelReader = ExcelReaderFactory.CreateBinaryReader(stream);

                        excelReader.IsFirstRowAsColumnNames = true;
                        DataSet result = excelReader.AsDataSet();

                        DataTable myTable = result.Tables[0];

                        excelReader.Close();
                        return result;
                    }
                    else if (fileExtension == ".xlsx")
                    {
                        excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

                        //excelReader.IsFirstRowAsColumnNames = true;
                        DataSet result = excelReader.AsDataSet();

                        DataTable myTable = result.Tables[0];

                        excelReader.Close();
                        return result;
                    }
                    else if (fileExtension == ".csv")
                    {
                        //Someone else can implement this
                        return null;
                    }
                    else
                    {
                        throw new Exception("Unhandled Filetype");
                    }
                }
                catch
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
开发者ID:redtchits,项目名称:RCM,代码行数:58,代码来源:Utils.cs

示例11: GetBannerPath

 public Tuple<string, string> GetBannerPath(string programId, HttpServerUtility Server)
 {
     var banner = DefaultBanner;
     var banner2x = DefaultBanner2x;
     if (!string.IsNullOrEmpty(programId))
     {
         var programBanner = string.Format("~/images/Banners/{0}.png",
                                           programId);
         var programBanner2x = string.Format("~/images/Banners/{0}@2x.png",
                                             programId);
         if (File.Exists(Server.MapPath(programBanner)))
         {
             banner = programBanner;
             if (File.Exists(Server.MapPath(programBanner2x)))
             {
                 banner2x = programBanner2x;
             }
             else
             {
                 banner2x = null;
             }
         }
         else
         {
             programBanner = string.Format("~/images/Banners/{0}.jpg",
                                           programId);
             programBanner2x = string.Format("~/images/Banners/{0}@2x.jpg",
                                             programId);
             if (File.Exists(Server.MapPath(programBanner)))
             {
                 banner = programBanner;
                 if (File.Exists(Server.MapPath(programBanner2x)))
                 {
                     banner2x = programBanner2x;
                 }
                 else
                 {
                     banner2x = null;
                 }
             }
         }
     }
     return new Tuple<string, string>(banner, banner2x);
 }
开发者ID:justinmeiners,项目名称:greatreadingadventure,代码行数:44,代码来源:Banner.cs

示例12: Init

        public static void Init(HttpServerUtility server)
        {
            lock (_lock)
            {
                if (Debugger.IsAttached)
                    BasicConfigurator.Configure();
                else
                    XmlConfigurator.Configure();

                string configPath = Path.Combine(PARENT_CONFIG_PATH, DefaultConfigName);
                DefaultConfigPath = server.MapPath(configPath);

                RootDir = server.MapPath(".");

                log.Debug("DYLD_FALLBACK_LIBRARY_PATH: " + Environment.GetEnvironmentVariable("DYLD_FALLBACK_LIBRARY_PATH"));
                log.Debug("PWD: " + Environment.CurrentDirectory);

                //By default if there's no config let's create a sqlite db.
                string defaultConfigPath = DefaultConfigPath;

                string sqlitePath = Path.Combine(DATA_FOLDER, DEFAULT_SQLITE_NAME);
                sqlitePath = server.MapPath(sqlitePath);

                if (!File.Exists(defaultConfigPath))
                {
                    ConfigFile file = new ConfigFile(defaultConfigPath);

                    file.Set(DbConstants.KEY_DB_TYPE, DbConstants.DB_TYPE_SQLITE);
                    file.Set(DbConstants.KEY_FILE_NAME, sqlitePath);
                    file.Save();

                    CurrentConfigFile = file;
                }
                else
                {
                    CurrentConfigFile = new ConfigFile(defaultConfigPath);
                    CurrentConfigFile.Load();
                }

                CurrentDbProvider = DbProviderFactory.Create(CurrentConfigFile);
                _inited = true;
            }

        }
开发者ID:ldemidov,项目名称:WebGoat.NET,代码行数:44,代码来源:Settings.cs

示例13: PopulateSampleFiles

		public void PopulateSampleFiles(HttpServerUtility server, string wildcard, DropDownList ddl)
		{
			string sampleDir = server.MapPath("SampleFiles");
			ddl.Items.Add(new ListItem("Choose sample", ""));
			DirectoryInfo di = new DirectoryInfo(sampleDir);
			foreach (FileInfo f in di.GetFiles(wildcard))
			{
				ddl.Items.Add(new ListItem(Path.GetFileNameWithoutExtension(f.Name), f.Name));
			}
		}
开发者ID:relaxar,项目名称:reko,代码行数:10,代码来源:WebDecompilerHost.cs

示例14: RegisterStandard

        public static Bootstrapper RegisterStandard(this Bootstrapper bootstrapper, HttpServerUtility server)
        {
            FileSystemStorage.StoragePath = server.MapPath("~/Storage");
            FormsCore.Instance.BaseUrl = "http://localhost:36258";

            bootstrapper.UnityContainer
                .RegisterType<IFileStorage, FileSystemStorage>()
                .RegisterType<ILogger, TraceLogger>();

            return bootstrapper;
        }
开发者ID:jacklau88,项目名称:Forms,代码行数:11,代码来源:BootstrapperExtensions.cs

示例15: Initialize

        public static void Initialize(HttpServerUtility server)
        {
            FileName = server.MapPath ("~/App_Data/Structure.json");

            _contentManager.Synchronize("Bifrost");

            if (_structure == null)
                Load ();

            if (_structure == null)
                Generate ();
        }
开发者ID:dolittle,项目名称:ProjectPages,代码行数:12,代码来源:DocumentationContent.ashx.cs


注:本文中的System.Web.HttpServerUtility.MapPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。