本文整理汇总了C#中System.Web.HttpResponseBase.ClearHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.ClearHeaders方法的具体用法?C# HttpResponseBase.ClearHeaders怎么用?C# HttpResponseBase.ClearHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.ClearHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: WriteToHttpResponse
/// <summary>
/// Exports the chart to the specified HttpResponse object. This method
/// is preferred over WriteToStream() because it handles clearing the
/// output stream and setting the HTTP reponse headers.
/// </summary>
/// <param name="httpResponse"></param>
public void WriteToHttpResponse(HttpResponseBase httpResponse)
{
httpResponse.ClearContent();
httpResponse.ClearHeaders();
httpResponse.ContentType = this.ContentType;
httpResponse.AddHeader("Content-Disposition", this.ContentDisposition);
WriteToStream(httpResponse.OutputStream);
}
示例3: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.BufferOutput = false;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Cookies.Clear();
response.ContentType = ContentType;
response.ContentEncoding = Encoding.Default;
response.AddHeader("Content-Type", ContentType);
response.AddHeader("Content-Disposition",
String.Format("attachment; filename={0}",
this.FileDownloadName));
byte[] buffer = new byte[4096];
using (ZipOutputStream zipOutputStream =
new ZipOutputStream(response.OutputStream))
{
foreach (string fileName in FilesToZip)
{
int folderOffset = fileName.LastIndexOf('\\');
Stream fs = System.IO.File.OpenRead(fileName); // or any suitable inputstream
string entryName = fileName.Substring(folderOffset);
ZipEntry entry = new ZipEntry(ZipEntry.CleanName(entryName));
entry.Size = fs.Length;
// Setting the Size provides WinXP built-in extractor compatibility,
// but if not available, you can set zipOutputStream.UseZip64 = UseZip64.Off instead.
zipOutputStream.PutNextEntry(entry);
//zipOutputStream.SetLevel(3); // 0-9 for compression level
//zipOutputStream.Password(); // security
int count = fs.Read(buffer, 0, buffer.Length);
while (count > 0)
{
zipOutputStream.Write(buffer, 0, count);
count = fs.Read(buffer, 0, buffer.Length);
if (!response.IsClientConnected)
{
break;
}
response.Flush();
}
fs.Close();
}
zipOutputStream.Finish();
}
//response.OutputStream.Flush();
response.End();
}