本文整理汇总了C#中System.Web.HttpResponse.WriteFile方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.WriteFile方法的具体用法?C# HttpResponse.WriteFile怎么用?C# HttpResponse.WriteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.WriteFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Real
private void Real(HttpResponse response, HttpRequest request)
{
if (File.Exists(request.PhysicalPath))
{
FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
response.Clear();
response.AddHeader("Content-Disposition", "filename=" + file.Name);
response.AddHeader("Content-Length", file.Length.ToString());
string fileExtension = file.Extension.ToLower();
switch (fileExtension)
{
case ".mp3":
response.ContentType = "audio/mpeg3";
break;
case ".mpeg":
response.ContentType = "video/mpeg";
break;
case ".jpg":
response.ContentType = "image/jpeg";
break;
case ".bmp":
response.ContentType = "image/bmp";
break;
case ".gif":
response.ContentType = "image/gif";
break;
case ".doc":
response.ContentType = "application/msword";
break;
case ".css":
response.ContentType = "text/css";
break;
case ".html":
response.ContentType = "text/html";
break;
case ".htm":
response.ContentType = "text/html";
break;
case ".swf":
response.ContentType = "application/x-shockwave-flash";
break;
case ".exe":
response.ContentType = "application/octet-stream";
break;
case ".inf":
response.ContentType = "application/x-texinfo";
break;
default:
response.ContentType = "application/octet-stream";
break;
}
response.WriteFile(file.FullName);
response.End();
}
else
{
response.Write("File Not Exists");
}
}
示例2: Real
private void Real(HttpResponse response, HttpRequest request)
{
if (File.Exists(request.PhysicalPath))
{
FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
response.Clear();
response.AddHeader("Content-Disposition", "filename=" + file.Name);
response.AddHeader("Content-Length", file.Length.ToString());
string fileExtension = file.Extension.ToLower();
switch (fileExtension)
{
case ".jpg":
response.ContentType = "image/jpeg";
break;
case ".gif":
response.ContentType = "image/gif";
break;
case ".png":
response.ContentType = "image/png";
break;
default:
response.ContentType = "application/octet-stream";
break;
}
response.WriteFile(file.FullName);
response.End();
}
else
{
response.Write("File Not Exists");
}
}
示例3: WriteFile
private static void WriteFile(HttpResponse response, HttpRequest request, string virtualPath)
{
var filePath = GetRealLocation(request, virtualPath);
if (filePath != null && File.Exists(filePath))
{
response.ContentType = "application/javascript";
response.WriteFile(Path.GetFileName(filePath));
}
else
Return404(response);
}
示例4: SendToResponse
/// <summary>
/// Sends the file to the response with content-length header. will check last-writetime for sending modified header
/// </summary>
/// <param name="Response"></param>
/// <param name="file"></param>
/// <param name="mimetype"></param>
/// <remarks>Works with all types of files, not image specific</remarks>
public void SendToResponse(HttpResponse Response, FileInfo file, string mimetype)
{
Response.ClearHeaders();
setCacheHeaders(Response);
//Response.Cache.SetETag("\"999ed196eeb0cc1:9\"");
Response.Cache.SetLastModified(file.LastWriteTime);
Response.ContentType = mimetype;
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.WriteFile(file.FullName);
Response.End();
}
示例5: WriteResponse
/// <summary>
/// 写入文件到http回应中
/// </summary>
/// <param name="response"></param>
public void WriteResponse(HttpResponse response) {
// 设置文件的最后修改时间
var lastModified = File.GetLastWriteTimeUtc(FilePath).Truncate();
response.Cache.SetLastModified(lastModified);
// 文件没有修改时返回304
if (IfModifiedSince != null && IfModifiedSince == lastModified) {
response.StatusCode = 304;
response.SuppressContent = true;
return;
}
// 写入文件到http回应中
response.ContentType = MimeMapping.GetMimeMapping(FilePath);
response.WriteFile(FilePath);
}
示例6: Exportar
public static void Exportar(string nombreArchivo, IList titulos, IList propiedades, IList elementos, HttpResponse response, string tituloPrincipal)
{
string pathArchivo = ConfigurationManager.AppSettings["PATH_TEMP"] + nombreArchivo;
FileInfo archivo = new FileInfo(pathArchivo);
StreamWriter handlerArchivo = archivo.CreateText();
handlerArchivo.WriteLine(tituloPrincipal);
// Escribir encabezado
string linea = "";
foreach (string titulo in titulos)
{
linea += "=CONCATENAR(\"\";\"" + titulo + "\";\"\")\t";
}
handlerArchivo.WriteLine(linea);
// Escribir contenido
foreach (object elemento in elementos)
{
linea = "";
foreach (string propiedad in propiedades)
{
linea += "=CONCATENAR(\"\";\"" + ReflectionUtils.GetProperty(elemento, propiedad) + "\";\"\")\t";
}
handlerArchivo.WriteLine(linea);
}
// Genero la salida
handlerArchivo.Close();
response.AppendHeader("content-disposition", "attachment; filename=" + nombreArchivo);
response.ContentType = "application / msexcel";
response.WriteFile(pathArchivo);
response.End();
}
示例7: WriteResponse
/// <summary>
/// 渡された HttpResponse にレスポンスを書き込みます。
/// </summary>
public override void WriteResponse(HttpResponse response){
WriteResponseHeader(response);
WriteAdditionalHeader(response);
SetLastModified(response);
response.WriteFile(FileSource.FullName);
}
示例8: print_bug
///////////////////////////////////////////////////////////////////////
public static void print_bug (HttpResponse Response, DataRow dr, IIdentity identity, bool include_style, bool images_inline, bool history_inline, bool internal_posts)
{
int bugid = Convert.ToInt32(dr["id"]);
string string_bugid = Convert.ToString(bugid);
if (include_style) // when sending emails
{
Response.Write("\n<style>\n");
// If this file exists, use it.
string css_for_email_file = Util.GetAbsolutePath("custom\\btnet_css_for_email.css");
try
{
if (System.IO.File.Exists(css_for_email_file))
{
Response.WriteFile(css_for_email_file);
Response.Write("\n");
}
else
{
css_for_email_file = Util.GetAbsolutePath("btnet_base.css");
Response.WriteFile(css_for_email_file);
Response.Write("\n");
css_for_email_file = Util.GetAbsolutePath("custom\\btnet_custom.css");
if (System.IO.File.Exists(css_for_email_file))
{
Response.WriteFile(css_for_email_file);
Response.Write("\n");
}
}
}
catch (Exception e)
{
btnet.Util.write_to_log("Exception trying to read css file for email \""
+ css_for_email_file
+ "\":"
+ e.Message);
}
// underline links in the emails to make them more obvious
Response.Write("\na {text-decoration: underline; }");
Response.Write("\na:visited {text-decoration: underline; }");
Response.Write("\na:hover {text-decoration: underline; }");
Response.Write("\n</style>\n");
}
Response.Write ("<body style='background:white'>");
Response.Write ("<b>"
+ btnet.Util.capitalize_first_letter(btnet.Util.get_setting("SingularBugLabel","bug"))
+ " ID: <a href="
+ btnet.Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
+ "edit_bug.aspx?id="
+ string_bugid
+ ">"
+ string_bugid
+ "</a>");
if (btnet.Util.get_setting("EnableMobile", "0") == "1")
{
Response.Write(
" Mobile link: <a href="
+ btnet.Util.get_setting("AbsoluteUrlPrefix", "http://127.0.0.1/")
+ "mbug.aspx?id="
+ string_bugid
+ ">"
+ btnet.Util.get_setting("AbsoluteUrlPrefix", "http://127.0.0.1/")
+ "mbug.aspx?id="
+ string_bugid
+ "</a>");
}
Response.Write("<br>");
Response.Write ("Short desc: <a href="
+ btnet.Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
+ "edit_bug.aspx?id="
+ string_bugid
+ ">"
+ HttpUtility.HtmlEncode((string)dr["short_desc"])
+ "</a></b><p>");
// start of the table with the bug fields
Response.Write ("\n<table border=1 cellpadding=3 cellspacing=0>");
Response.Write("\n<tr><td>Last changed by<td>"
+ format_username((string)dr["last_updated_user"],(string)dr["last_updated_fullname"])
+ " ");
Response.Write("\n<tr><td>Reported By<td>"
+ format_username((string)dr["reporter"],(string)dr["reporter_fullname"])
+ " ");
Response.Write("\n<tr><td>Reported On<td>" + btnet.Util.format_db_date_and_time(dr["reported_date"]) + " ");
if (identity.GetTagsFieldPermissionLevel() > 0)
Response.Write("\n<tr><td>Tags<td>" + dr["bg_tags"] + " ");
if (identity.GetProjectFieldPermissionLevel() > 0)
//.........这里部分代码省略.........
示例9: DownloadFile
/// <summary>
/// Writes file to response.
/// </summary>
public void DownloadFile(String path, String localFileName, String originalFileName,
String contentType, HttpResponse response)
{
if (!System.IO.File.Exists(path + localFileName))
{
return;
}
response.ClearContent();
response.ClearHeaders();
response.ContentType = contentType;
response.AddHeader("content-disposition",
"attachment; filename=" + originalFileName);
response.WriteFile(path + localFileName);
response.End();
}
示例10: SendResponse
//.........这里部分代码省略.........
{
response.AddHeader("X-CKFinder-Error", Errors.ThumbnailsDisabled.ToString());
response.StatusCode = 403;
response.End();
return;
}
if (!CurrentFolder.CheckAcl(AccessControlRules.FileView))
{
response.AddHeader("X-CKFinder-Error", Errors.Unauthorized.ToString());
response.StatusCode = 403;
response.End();
return;
}
bool is304 = false;
string fileName = HttpContext.Current.Request["FileName"];
string thumbFilePath = Path.Combine(CurrentFolder.ThumbsServerPath, fileName.Replace("/", "\\"));
if (!Connector.CheckFileName(fileName))
{
response.AddHeader("X-CKFinder-Error", Errors.InvalidRequest.ToString());
response.StatusCode = 403;
response.End();
return;
}
if (Config.Current.CheckIsHiddenFile(fileName))
{
response.AddHeader("X-CKFinder-Error", string.Format("{0} - Hidden folder", Errors.FileNotFound));
response.StatusCode = 404;
response.End();
return;
}
// If the thumbnail file doesn't exists, create it now.
if (!File.Exists(thumbFilePath))
{
string sourceFilePath = Path.Combine(CurrentFolder.ServerPath, fileName);
if (!File.Exists(sourceFilePath))
{
response.AddHeader("X-CKFinder-Error", Errors.FileNotFound.ToString());
response.StatusCode = 404;
response.End();
return;
}
ImageTools.ResizeImage(sourceFilePath, thumbFilePath, Config.Current.Thumbnails.MaxWidth, Config.Current.Thumbnails.MaxHeight, true, Config.Current.Thumbnails.Quality);
}
var thumbfile = new FileInfo(thumbFilePath);
string eTag = thumbfile.LastWriteTime.Ticks.ToString("X") + "-" + thumbfile.Length.ToString("X");
string chachedETag = Request.ServerVariables["HTTP_IF_NONE_MATCH"];
if (!string.IsNullOrEmpty(chachedETag) && eTag == chachedETag)
is304 = true;
if (!is304)
{
string cachedTimeStr = Request.ServerVariables["HTTP_IF_MODIFIED_SINCE"];
if (!string.IsNullOrEmpty(cachedTimeStr))
{
try
{
DateTime cachedTime = DateTime.Parse(cachedTimeStr);
if (cachedTime >= thumbfile.LastWriteTime)
is304 = true;
}
catch
{
is304 = false;
}
}
}
if (is304)
{
response.StatusCode = 304;
response.End();
return;
}
string thumbFileExt = Path.GetExtension(thumbFilePath).TrimStart('.').ToLower();
if (thumbFilePath == ".jpg")
response.ContentType = "image/jpeg";
else
response.ContentType = "image/" + thumbFileExt;
response.Cache.SetETag(eTag);
response.Cache.SetLastModified(thumbfile.LastWriteTime);
response.Cache.SetCacheability(HttpCacheability.Private);
response.WriteFile(thumbFilePath);
}
示例11: WriteFile_PermitOnly_UnmanagedCode
public void WriteFile_PermitOnly_UnmanagedCode ()
{
HttpResponse response = new HttpResponse (writer);
response.WriteFile (handle, 0, 1);
}
示例12: WriteResponse
public override void WriteResponse(HttpResponse response)
{
response.ContentType = this.ContentType;
if(myFile.Exists) response.WriteFile(myFile.FullName);
}
示例13: transmitify
void transmitify(HttpResponse response, FileInfo fi)
{
response.StatusCode = 200;
response.AddHeader("ETag", fi.LastWriteTimeUtc.Ticks.ToString("x"));
response.AddHeader("Content-Type", _compiler.OutputMimeType);
response.AddHeader("Content-Disposition", "inline");
response.AddHeader("Last-Modified", fi.LastWriteTimeUtc.ToString("R"));
response.WriteFile(fi.FullName);
}
示例14: HandleTransactionRequest
/// <summary>
/// Returns the XML for the requested transaction and removes any state files associated with it.
/// </summary>
/// <param name="response"><see cref="T:System.Web.HttpResponse"/></param>
/// <param name="transaction">Transaction TcmUri</param>
private void HandleTransactionRequest(HttpResponse response, String transaction)
{
Logger.Info("FileTransaction - Requested '{0}'.", transaction);
if (TcmUri.IsValid(transaction))
{
String mappedFile = Path.Combine(mIncomingFolder, transaction + ".xml");
if (File.Exists(mappedFile))
{
response.ContentType = "text/xml";
response.WriteFile(mappedFile);
try
{
String stateFile = Path.Combine(mIncomingFolder, transaction + ".state.xml");
Logger.Debug("Removing transaction state xml '{0}'.", stateFile);
if (File.Exists(stateFile))
File.Delete(stateFile);
}
catch (Exception ex)
{
Logger.Error("FileTransaction - Removing '{0}'.", ex, ex.Message);
}
return;
}
Logger.Warning("FileTransaction - Not found transaction file '{0}'.", mappedFile);
}
Logger.Warning("FileTransaction - Invalid transaction '{0}'.", transaction);
response.StatusCode = (int)HttpStatusCode.NoContent;
response.Write("No Content");
}
示例15: HandleFileRequest
/// <summary>
/// Handles "fileName=" requests from the cd_transport service
/// </summary>
/// <param name="response"><see cref="T:System.Web.HttpResponse"/></param>
/// <param name="fileName">fileName</param>
/// <param name="action">action to take, either empty or "remove"</param>
private void HandleFileRequest(HttpResponse response, String fileName, String action)
{
String mappedFile = TcmUri.IsValid(fileName) ? Path.Combine(mIncomingFolder, fileName + ".state.xml") : Path.Combine(mIncomingFolder, fileName);
Logger.Info("FileRequest - fileName '{0}', action '{1}'.", fileName, action);
if (File.Exists(mappedFile))
{
if (String.Equals(action, "remove", StringComparison.OrdinalIgnoreCase))
{
try
{
Logger.Info("FileRequest - removing file '{0}'.", fileName);
File.Delete(mappedFile);
}
catch (Exception ex)
{
Logger.Error("FileRequest - removing file", ex, ex.Message);
}
response.Write("File removed");
return;
}
else
{
if (String.Equals(Path.GetExtension(mappedFile), ".xml", StringComparison.OrdinalIgnoreCase))
{
response.ContentType = "text/xml";
if (String.Equals(fileName, META_XML, StringComparison.OrdinalIgnoreCase))
{
CleanTransactions.Execute();
Logger.Debug("FileRequest - meta.xml requested");
String metaXml = HttpContext.Current.Cache[META_XML] as String;
if (String.IsNullOrEmpty(metaXml))
{
metaXml = File.ReadAllText(mappedFile, Encoding.UTF8);
HttpContext.Current.Cache.Insert(META_XML, metaXml, new CacheDependency(mappedFile));
}
else
{
Logger.Info("FileRequest - Sending cached meta.xml");
}
response.Write(metaXml);
return;
}
}
Logger.Info("FileRequest - sending file {0}", fileName);
response.WriteFile(mappedFile);
return;
}
}
Logger.Warning("FileRequest - Not found or invalid '{0}'.", mappedFile);
response.StatusCode = (int)HttpStatusCode.NoContent;
response.Write("No Content");
}