本文整理汇总了C#中System.Web.HttpResponseBase.WriteFile方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.WriteFile方法的具体用法?C# HttpResponseBase.WriteFile怎么用?C# HttpResponseBase.WriteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.WriteFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleError
public static void HandleError(HttpServerUtilityBase server, HttpResponseBase response,
CustomErrorsSection customErrorsSection)
{
CustomError customError = GetCustomError(server.GetLastError(), customErrorsSection);
server.ClearError();
response.Clear();
response.WriteFile(customError.Redirect);
response.StatusCode = customError.StatusCode;
}
示例2: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
_isRssFeed = _feedType == FeedType.Rss;
// Creates Xml file.
string xmlFile = HttpContext.Current.Server.MapPath("~/feed.xml");
using (var fileStream = new FileStream(xmlFile, FileMode.Create))
{
using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
{
var xs = new XmlWriterSettings { Indent = true };
using (var xmlWriter = XmlWriter.Create(streamWriter, xs))
{
xmlWriter.WriteStartDocument();
if (_isCssStyles)
{
const string strPi = "type='text/css' href='/Contents/Styles/feedStyle.css'";
// Write processor information
xmlWriter.WriteProcessingInstruction("xml-stylesheet", strPi);
}
if (_isRssFeed)
{
// RSS 2.0
var rssFormatter = new Rss20FeedFormatter(_feed, true);
rssFormatter.WriteTo(xmlWriter);
}
else
{
// Atom 1.0
var atomFormatter = new Atom10FeedFormatter(_feed);
atomFormatter.WriteTo(xmlWriter);
}
}
}
}
//Display Xml file in browser.
response.Clear();
response.Buffer = true;
response.Charset = "";
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = "text/xml";
response.WriteFile(HttpContext.Current.Server.MapPath("~/feed.xml"));
response.Flush();
response.End();
}
示例3: FileDownload
public void FileDownload(HttpResponseBase response,string filePah)
{
if(!IsExists(filePah)) {
throw new Exception("�ļ�������");
}
var fileInfo = new FileInfo(filePah);
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name,System.Text.Encoding.UTF8));
response.AddHeader("Content-Length", fileInfo.Length.ToString());
//response.AddHeader("Content-Transfer-Encoding", "binary");
response.ContentType = "application/vnd.ms-excel;charset=UTF-8";
response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
response.WriteFile(fileInfo.FullName);
response.Flush();
response.End();
}
示例4: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
_isRssFeed = _feedType == FeedType.Rss;
// Creates Xml file.
string xmlFile = HttpContext.Current.Server.MapPath("~/feed.xml");
using (var fileStream = new FileStream(xmlFile, FileMode.Create))
{
using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
{
var xs = new XmlWriterSettings { Indent = true };
using (var xmlWriter = XmlWriter.Create(streamWriter, xs))
{
xmlWriter.WriteStartDocument();
if (_isRssFeed)
{
// RSS 2.0
var rssFormatter = new Rss20FeedFormatter(_feed);
rssFormatter.WriteTo(xmlWriter);
}
else
{
// Atom 1.0
var atomFormatter = new Atom10FeedFormatter(_feed);
atomFormatter.WriteTo(xmlWriter);
}
}
}
}
XslTransform myXslTransform = new XslTransform();
myXslTransform.Load(HttpContext.Current.Server.MapPath("~/feed.xslt"));
myXslTransform.Transform(HttpContext.Current.Server.MapPath("~/feed.xml"), HttpContext.Current.Server.MapPath("~/newFeed.xml"));
//Display Xml file in browser.
response.Clear();
response.Buffer = true;
response.Charset = "";
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = "application/xml";
response.WriteFile(HttpContext.Current.Server.MapPath("~/newFeed.xml"));
response.Flush();
response.End();
}
示例5: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.WriteFile(FileName, true);
}
示例6: Export
/// <summary>
/// Exports the specified response.
/// </summary>
/// <param name="response">The response.</param>
/// <param name="myPageName">Name of my page.</param>
/// <param name="columns">The columns.</param>
/// <param name="ds">The ds.</param>
/// <Remarks>
/// Created Time: 2008-8-4 10:59
/// Created By: jack_que
/// Last Modified Time:
/// Last Modified By:
/// </Remarks>
public static void Export(HttpResponseBase response, string myPageName, List<MESParameterInfo> columns, DataSet ds)
{
string path = AppDomain.CurrentDomain.BaseDirectory + @"\Excel\" + myPageName + ".xls";
response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=" + myPageName + ".xls");
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.ContentType = "application/ms-excel";
ExcelWriter excel = new ExcelWriter(path);
try
{
excel.BeginWrite();
short row = 0;
for (short k = 0; k < columns.Count; k++)
{
excel.WriteString(row, k, columns[k].ParamDisplayName);
}
DataTable dt = ds.Tables[0];
for (short i = 0; i < dt.Rows.Count; i++)
{
row++;
for (short j = 0; j < columns.Count; j++)
{
MESParameterInfo column = columns[j];
string columnType = column.ParamType;
string columnName = column.ParamName;
object value = ds.Tables[0].Rows[i][columnName];
if (columnType != null && columnType.Equals("date"))
{
value = value.ToString().Split(new char[] { ' ' }, StringSplitOptions.None)[0];
}
excel.WriteString(row, j, value.ToString());
}
}
}
finally
{
excel.EndWrite();
}
FileInfo file = new FileInfo(path);
if (file.Exists)
{
response.WriteFile(path);
response.Flush();
file.Delete();
}
}