本文整理汇总了C#中HttpResponse.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.Clear方法的具体用法?C# HttpResponse.Clear怎么用?C# HttpResponse.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.Clear方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(HttpContext context)
{
Response = context.Response;
Response.Clear();
string layer = context.Request.Form["layer"];
string ids = context.Request.Form["ids"];
WriteData(layer, ids);
}
示例2: WriteJsonData
//truyen json data len form
public static void WriteJsonData(HttpResponse response, Object obj)
{
response.Clear();
response.ClearContent();
response.ClearHeaders();
System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue, RecursionLimit = 100 };
string output = oSerializer.Serialize(obj);
response.ContentType = "Application/Json";
response.Write(output);
response.End();
}
示例3: ExportCSV
protected static void ExportCSV(HttpResponse response, string fileText, string fileName)
{
byte[] buffer = GetBytes(fileText);
try
{
response.Clear();
response.ContentType = "text/plain";
response.OutputStream.Write(buffer, 0, buffer.Length);
response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
response.End();
}
catch (System.Web.HttpException ex)
{
// ignore exception where user closed the download box
if (!ex.Message.StartsWith("The remote host closed the connection. The error code is"))
throw;
}
}
示例4: sendResponseAsJson
private void sendResponseAsJson(HttpResponse response, string responseString)
{
response.Clear();
response.BufferOutput = true;
response.StatusCode = 200; // HttpStatusCode.OK;
response.Write(responseString);
response.ContentType = "application/json; charset=utf-8";
response.End();
}
示例5: sendFile
private void sendFile(HttpResponse response, string fileName)
{
/*
* client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println();
*/
response.Clear();
response.BufferOutput = true;
response.StatusCode = 200; // HttpStatusCode.OK;
response.Write(SD.readAllFile(fileName));
response.ContentType = "text/html";
response.End();
}
示例6: ProcessImage
private void ProcessImage(HttpApplication app, HttpResponse Response, HttpRequest Request)
{
string file = Request.Path.Substring(4).ToLower(); // stripping out the /cms part ...
string output = "";
Response.Clear();
Response.ContentType = GetContentTypeOfFile(file);
int newWidth = 0;
int newHeight = 0;
int maxWidth = 0;
int maxHeight = 0;
if (Request["w"] != null)
newWidth = Convert.ToInt32(Request["w"].ToString());
if (Request["h"] != null)
newHeight = Convert.ToInt32(Request["h"].ToString());
if (Request["mw"] != null)
maxWidth = Convert.ToInt32(Request["mw"].ToString());
if (Request["mh"] != null)
maxHeight = Convert.ToInt32(Request["mh"].ToString());
try
{
if (newWidth > 0 || newHeight > 0 || maxHeight > 0 || maxWidth > 0)
{
// resize and render the image
// should cache it and reuse when possibl...
Image i = Image.FromFile(Request.MapPath(Request.Path));
using (MemoryStream ms = new MemoryStream())
{
int newWidth2 = newWidth;
int newHeight2 = newHeight;
if (newWidth > 0 && newHeight == 0)
newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth);
else if (newHeight > 0 && newWidth == 0)
newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight);
if (newHeight2 == 0) newHeight2 = i.Height;
if (newWidth2 == 0) newWidth2 = i.Width;
if (maxWidth > 0 && newWidth2 > maxWidth)
{
newWidth2 = maxWidth;
newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth2);
}
if (maxHeight > 0 && newHeight2 > maxHeight)
{
newHeight2 = maxHeight;
newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight2);
}
Bitmap i2 = new Bitmap(i, newWidth2, newHeight2);
i2.Save(ms, GetImageFormatOfFile(file));
Response.BinaryWrite(ms.ToArray());
}
}
else
{
// is there a way to call default handler instead of this??
Response.WriteFile(Request.MapPath(Request.Path));
}
}
catch
{
Response.WriteFile(Request.MapPath(Request.Path));
}
Response.End();
}
示例7: DownloadDocument
public static void DownloadDocument(HttpResponse httpResponse, byte[] fileContents, string fileName)
{
try
{
string contentType = "application/octet-stream";
try { contentType = Utilities.GetMimeType(System.IO.Path.GetExtension(fileName)); }
catch (Exception) { }
httpResponse.Clear();
httpResponse.ClearHeaders();
// add cooke so that javascript can detect when file downloaded is done and started if it want's to
// do something (such as letter print page to deselect leter to print)
httpResponse.Cookies["fileDownloaded"].Value = "true";
httpResponse.Cookies["fileDownloaded"].Expires = DateTime.Now.AddHours(3);
httpResponse.ContentType = contentType;
httpResponse.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
httpResponse.OutputStream.Write(fileContents, 0, fileContents.Length);
httpResponse.Flush();
httpResponse.End();
}
catch (System.Web.HttpException ex)
{
// ignore exception where user closed the download box
if (!ex.Message.StartsWith("The remote host closed the connection. The error code is"))
throw;
}
}
示例8: ExportExcel
/// <summary>
/// Export excel with binary format using ClosedXml library
/// </summary>
/// <param name="response">Current page response</param>
/// <param name="dt">DataTabe</param>
/// <param name="columnWidths">double array to define the with of column</param>
public static void ExportExcel(HttpResponse response, string fileName, DataTable dt, double[] columnWidths)
{
try
{
int numColumn = columnWidths.Length;
using (XLWorkbook wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add(dt);
using (MemoryStream MyMemoryStream = new MemoryStream())
{
ws.Tables.First().ShowAutoFilter = false;
ws.Tables.First().ShowRowStripes = false;
ws.Tables.First().Theme = XLTableTheme.None;
ws.SheetView.FreezeRows(1);
ws.Row(1).Style.Font.FontColor = XLColor.Black;
ws.Row(1).Style.Font.Bold = true;
ws.Row(1).Style.Alignment.Indent = 1;
ws.Range(1, 1, 1, numColumn).Style.Fill.BackgroundColor = XLColor.LightGreen;
ws.Column(1).Width = columnWidths[0];
if (columnWidths.Length == 18)
{
ws.Column(1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
}
ws.Column(1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
for (int i = 1; i < numColumn; i++)
{
ws.Column(i + 1).Width = columnWidths[i];
ws.Column(i + 1).Style.Alignment.WrapText = true;
ws.Column(i + 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
}
ws.RangeUsed().Style.Border.InsideBorderColor = XLColor.Black;
ws.RangeUsed().Style.Border.OutsideBorderColor = XLColor.Black;
ws.RangeUsed().Style.Border.InsideBorder = XLBorderStyleValues.Thin;
ws.RangeUsed().Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
wb.SaveAs(MyMemoryStream);
response.Clear();
response.Buffer = true;
response.Charset = "";
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
MyMemoryStream.WriteTo(response.OutputStream);
response.Flush();
response.End();
}
}
}
catch (Exception ex)
{
Pollinator.Common.Logger.Error("Error occured at " + typeof(ImportExportUltility).Name + " ExportExcel().:", ex);
response.End();
}
}
示例9: ExportCSV
public static int numFieldOfImportFile = 16; //number column of import file
#endregion Fields
#region Methods
/// <summary>
/// Export data to csv and response directly
/// </summary>
/// <param name="response">Current page response</param>
/// <param name="fileName">export file name</param>
/// <param name="listData">list data to export</param>
public static void ExportCSV(HttpResponse response, string fileName, List<ImportExportFields> listData)
{
//prepare the output stream
response.Clear();
response.Buffer = true;
// response.ContentType = "text/csv";
response.ContentType = "application/octet-stream";//application/vnd.ms-excel";
response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
//response.ContentEncoding = Encoding.Unicode;
response.ContentEncoding = System.Text.Encoding.UTF8;
response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
response.Write(DataToCsvString(listData));
response.Flush();
response.End();
}
示例10: OutputClientSireSelectionSheetsToPDF
private static void OutputClientSireSelectionSheetsToPDF(LocalReport localReport, string fileName, bool landscape,
bool legal, HttpResponse response)
{
const string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
// The DeviceInfo settings should be changed based on the reportType
// http://msdn2.microsoft.com/en-us/library/ms155397.aspx
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>" + (landscape ? (legal ? "14" : "11") : "8.5") + "in</PageWidth>" +
" <PageHeight>" + (landscape ? "8.5" : (legal ? "14" : "11")) + "in</PageHeight>" +
" <MarginTop>0.3in</MarginTop>" +
" <MarginLeft>1.25in</MarginLeft>" +
" <MarginRight>0.25in</MarginRight>" +
" <MarginBottom>0.3in</MarginBottom>" +
"</DeviceInfo>";
/* other attributes for the DeviceInfo are
StartPage - The first page of the report to render. A value of 0 indicates that all pages are rendered. The default value is 1.
Columns - The number of columns to set for the report. This value overrides the report's original settings.
ColumnSpacing - The column spacing to set for the report. This value overrides the report's original settings.
EndPage - The last page of the report to render. The default value is the value for StartPage.
*/
Warning[] warnings;
string[] streams;
//Render the report
byte[] renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
// Clear the response stream and write the bytes to the outputstream
// Set content-disposition to "attachment" so that user is prompted to take an action
// on the file (open or save)
response.Clear();
response.ContentType = mimeType;
response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + fileNameExtension);
response.BinaryWrite(renderedBytes);
response.End();
}
示例11: Write
public void Write(HttpResponse response, bool inline)
{
response.Clear();
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", (inline ? "inline" : "attachment") + "; filename=Map.pdf");
// create the PDF document
Configuration config = AppContext.GetConfiguration();
Configuration.PrintTemplateRow printTemplate = config.PrintTemplate.First(o => o.TemplateID == _templateId);
float pageWidth = Convert.ToSingle(printTemplate.PageWidth * PointsPerInch);
float pageHeight = Convert.ToSingle(printTemplate.PageHeight * PointsPerInch);
Rectangle pageSize = new Rectangle(pageWidth, pageHeight);
pageSize.BackgroundColor = new Color(System.Drawing.Color.White);
Document document = new Document(pageSize);
PdfWriter writer = PdfWriter.GetInstance(document, response.OutputStream);
document.Open();
PdfContentByte content = writer.DirectContent;
// get the extent of the main map and fit it to the proportions of
// the map box on the page
double mapScale = 0;
Configuration.PrintTemplateContentRow mapElement = printTemplate.GetPrintTemplateContentRows().FirstOrDefault(o => o.ContentType == "map");
if (mapElement != null)
{
if (_preserveMode == PreserveMode.Extent)
{
_appState.Extent.Reaspect(mapElement.Width, mapElement.Height);
}
else
{
IPoint c = new Point(_appState.Extent.Centre);
double dx;
double dy;
if (_preserveMode == PreserveMode.Scale)
{
double ratio = _appState.Extent.Width * 96 / _originalWidth;
dx = mapElement.Width * ratio * 0.5;
dy = mapElement.Height * ratio * 0.5;
}
else
{
dx = _appState.Extent.Width * 0.5;
dy = dx * mapElement.Height / mapElement.Width;
}
_appState.Extent = new Envelope(new Coordinate(c.Coordinate.X - dx, c.Coordinate.Y - dy), new Coordinate(c.Coordinate.X + dx, c.Coordinate.Y + dy));
}
double conversion = AppSettings.MapUnits == "feet" ? 1 : Constants.FeetPerMeter;
mapScale = _appState.Extent.Width * conversion / mapElement.Width;
_pixelSize = _appState.Extent.Width / (mapElement.Width * PixelsPerInch);
}
int inputIndex = 0;
// get the page template elements and draw each one to the page
foreach (Configuration.PrintTemplateContentRow element in printTemplate.GetPrintTemplateContentRows())
{
switch (element.ContentType)
{
case "box":
CreatePdfBox(content, element);
break;
case "date":
CreatePdfText(content, element, DateTime.Now.ToString("MMMM d, yyyy"));
break;
case "image":
CreatePdfImage(content, element);
break;
case "legend":
CreatePdfLegend(content, element);
break;
case "map":
CreatePdfMap(content, element);
break;
case "overviewmap":
CreatePdfOverviewMap(content, element);
break;
case "scale":
if (mapScale > 0)
{
CreatePdfText(content, element, "1\" = " + mapScale.ToString("0") + " ft");
}
//.........这里部分代码省略.........
示例12: ExportToCSV
private void ExportToCSV(string exportContent, HttpResponse response)
{
response.Clear();
response.AddHeader("content-disposition", "attachment;filename=" + fileName);
response.Charset = "";
response.ContentType = "application/octet-stream";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
response.Write(exportContent);
response.End();
}
示例13: ProcessRequest
public void ProcessRequest(HttpContext context)
{
Response = context.Response;
string appId = context.Request.QueryString["app"];
int groupId;
if (!String.IsNullOrEmpty(appId) && Int32.TryParse(context.Request.QueryString["group"], out groupId))
{
Response.Clear();
List<String> placemarks = new List<String>();
Dictionary<String, String> styles = new Dictionary<String, String>();
string appName = null;
string groupName = null;
using (OleDbConnection connection = AppContext.GetDatabaseConnection())
{
string sql = String.Format("update {0}MarkupGroup set DateLastAccessed = ? where GroupID = ?", AppSettings.ConfigurationTablePrefix);
using (OleDbCommand command = new OleDbCommand(sql, connection))
{
command.Parameters.Add("@1", OleDbType.Date).Value = DateTime.Now;
command.Parameters.Add("@2", OleDbType.Integer).Value = groupId;
command.ExecuteNonQuery();
command.CommandText = String.Format("select Shape, Color, Text from {0}Markup where GroupID = ? and Deleted = 0", AppSettings.ConfigurationTablePrefix);
command.Parameters.Clear();
command.Parameters.Add("@1", OleDbType.Integer).Value = groupId;
WKTReader wktReader = new WKTReader();
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
IGeometry geometry = wktReader.Read(reader.GetString(0));
string coordinates = GetCoordinates(geometry);
string color = reader.GetString(1);
bool isText = !reader.IsDBNull(2);
string styleId = GetStyle(geometry.OgcGeometryType, color, isText, styles);
switch (geometry.OgcGeometryType)
{
case OgcGeometryType.Point:
string name = isText ? String.Format("<name>{0}</name>", reader.GetString(2)) : "";
placemarks.Add(String.Format("<Placemark>{0}<styleUrl>#{1}</styleUrl><Point>{2}</Point></Placemark>", name, styleId, coordinates));
break;
case OgcGeometryType.LineString:
placemarks.Add(String.Format("<Placemark><styleUrl>#{0}</styleUrl><LineString>{1}</LineString></Placemark>", styleId, coordinates));
break;
case OgcGeometryType.Polygon:
placemarks.Add(String.Format("<Placemark><styleUrl>#{0}</styleUrl><Polygon><outerBoundaryIs><LinearRing>{1}</LinearRing></outerBoundaryIs></Polygon></Placemark>", styleId, coordinates));
break;
}
}
}
Configuration config = AppContext.GetConfiguration();
Configuration.ApplicationRow application = config.Application.Select(String.Format("ApplicationID = '{0}'", appId))[0] as Configuration.ApplicationRow;
appName = application.DisplayName;
command.CommandText = String.Format("select DisplayName from {0}MarkupGroup where GroupID = ?", AppSettings.ConfigurationTablePrefix);
groupName = command.ExecuteScalar() as string;
}
}
string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmssff");
string kmzName = String.Format("Markup_{0}.kmz", timeStamp);
string kmlName = String.Format("Markup_{0}.kml", timeStamp);
string kml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<kml xmlns=""http://earth.google.com/kml/2.2"">
<Folder>
<name>{0}</name>
<Document>
<name>Markup: {1}</name>
{2}
{3}
</Document>
</Folder>
</kml>";
string[] styleArray = new string[styles.Values.Count];
styles.Values.CopyTo(styleArray, 0);
kml = String.Format(kml, appName, groupName, String.Join("", styleArray), String.Join("", placemarks.ToArray()));
Response.ContentType = "application/vnd.google-earth.kmz";
Response.AddHeader("Content-Disposition", "attachment; filename=" + kmzName);
ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream);
MemoryStream memoryStream = new MemoryStream();
byte[] buffer = (new UTF8Encoding()).GetBytes(kml);
ZipEntry entry = new ZipEntry(kmlName);
//.........这里部分代码省略.........
示例14: ReturnImage
protected void ReturnImage(HttpResponse response, string path, string requestedETag)
{
response.Clear();
var responseETag = LookupEtagFromInput(path);
if (requestedETag == responseETag)
{
response.StatusCode = 304;
response.StatusDescription = "Not Modified";
response.AppendHeader("Content-Length", "0");
response.AppendHeader("Connection", "Close");
response.End();
}
response.ContentType = GetContentType(path);
response.TransmitFile(path);
response.AppendHeader("Connection", "Keep-Alive");
// set cache info
response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
response.Cache.VaryByHeaders["If-Modified-Since"] = true;
response.Cache.VaryByHeaders["If-None-Match"] = true;
response.Cache.SetLastModified(File.GetLastWriteTime(path));
response.Cache.SetETag(responseETag);
response.End();
}