本文整理汇总了C#中System.Web.HttpServerUtility类的典型用法代码示例。如果您正苦于以下问题:C# HttpServerUtility类的具体用法?C# HttpServerUtility怎么用?C# HttpServerUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpServerUtility类属于System.Web命名空间,在下文中一共展示了HttpServerUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: TextFileStatistics
/// <summary>
/// Returns a string for an HTML table with
/// number of bytes
/// number of lines
/// creation date,
/// last modification date
/// for the file with the given tildeFilePath.
/// </summary>
/// <param name="server">The server to convert to real file paths</param>
/// <param name="tildeFilePath">The tilde file path</param>
public static string TextFileStatistics(HttpServerUtility server, string tildeFilePath)
{
StringBuilder builder = new StringBuilder();
string filePath = null;
FileInfo info = null;
if (TildeFilePathExistsAndIsText(server, tildeFilePath, ref filePath, ref info))
{
long bytes = info.Length;
DateTime created = info.CreationTime;
DateTime modified = info.LastWriteTime;
long lines = 0;
using (StreamReader reader = new StreamReader(filePath))
{
while (!reader.EndOfStream)
{
string foobar = reader.ReadLine();
lines++;
}
}
TildeFilePathStatisticsTable(builder, bytes, lines, created, modified);
}
else
{
TildeFilePathErrorMessage(builder);
}
return builder.ToString();
}
示例3: 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;
}
示例4: 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;
}
示例5: 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);
}
示例6: 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();
}
}
示例7: transferToError
/**
* Transfers control to the Error page using Server.Transfer, and displays some error information.
*
* header: The error page header, ex. "Page not found". HTML in the string is not escaped.
* description: A description of the error, ex. "Path /foo/bar.txt not found". HTML in the string is not escaped.
* code: The response code of the page, ex. 404.
*/
public static void transferToError(HttpServerUtility server, HttpContext context, string header, string description, int code) {
context.Items.Clear ();
context.Items ["ErrorPage_title"] = header;
context.Items ["ErrorPage_desc"] = description;
context.Items ["ErrorPage_code"] = code;
server.Transfer ("~/ErrorPage.aspx", false);
}
示例8: FileInfo
/// <summary>
/// Returns true if the tildeFilePath corresponds to a file that
/// exists and is a text file.
///
/// In that case, the filePath and info parameters are initialized.
/// </summary>
/// <param name="server">The server to convert to real file paths</param>
/// <param name="tildeFilePath">The tilde file path</param>
/// <param name="filePath">The real file path</param>
/// <param name="info">The FileInfo object</param>
public static bool TildeFilePathExistsAndIsText
(HttpServerUtility server,
string tildeFilePath,
ref string filePath,
ref FileInfo info)
{
bool error = StringTools.IsTrivial(tildeFilePath);
if (!error)
{
error = !tildeFilePath.StartsWith("~/");
}
if (!error)
{
int category = FileTools.GetFileCategory(tildeFilePath);
error = category != FileTools.TEXT;
}
if (!error)
{
try
{
filePath = server.MapPath(tildeFilePath);
info = new FileInfo(filePath);
long bytes = info.Length;
}
catch
{
error = true;
}
}
return !error;
}
示例9: HttpServerUtilityWrapper
public HttpServerUtilityWrapper(HttpServerUtility httpServerUtility)
{
if (httpServerUtility == null) {
throw new ArgumentNullException("httpServerUtility");
}
_httpServerUtility = httpServerUtility;
}
示例10: ICalProducer
public ICalProducer(List<CalendarEntry> entries, string location, HttpServerUtility server, string personelNumber, string kardexNumber)
{
_entries = entries;
_location = location;
_server = server;
_personelNumber = personelNumber;
_kardexNumber = kardexNumber;
}
示例11: Start
public static void Start(HttpServerUtility server)
{
DeNSo.Configuration.BasePath = server.MapPath("~/App_Data");
DeNSo.Configuration.EnableJournaling = true;
Session.DefaultDataBase = "densodb_webapp";
Session.Start();
}
示例12: 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);
}
示例13: 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;
}
}
示例14: SetEndOfSendNotification
public override void SetEndOfSendNotification(
EndOfSendNotification callback_in,
object extraData_in
) {
base.SetEndOfSendNotification(callback_in, extraData_in);
server_ = ((HttpContext)extraData_in).Server;
}
示例15: ContextRequest
public ContextRequest(HttpContext context)
{
if (context == null)
throw new ArgumentNullException("context");
_request = context.Request;
_server = context.Server;
}