本文整理汇总了C#中System.Web.HttpResponseBase.BinaryWrite方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.BinaryWrite方法的具体用法?C# HttpResponseBase.BinaryWrite怎么用?C# HttpResponseBase.BinaryWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.BinaryWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyContents
/// <summary>
/// Copies the full binary contents of the given blob to the given HTTP response.
/// </summary>
private static void CopyContents(CloudBlob blob, HttpResponseBase response, long offset = 0)
{
blob.FetchAttributes();
response.BufferOutput = false;
response.AddHeader("Content-Length", blob.Attributes.Properties.Length.ToString());
response.Flush();
using (var reader = blob.OpenRead())
{
reader.Seek(offset, System.IO.SeekOrigin.Begin);
byte[] buffer = new byte[1024 * 4]; // 4KB buffer
while (reader.CanRead)
{
int numBytes = reader.Read(buffer, 0, buffer.Length);
if (numBytes <= 0)
break;
response.BinaryWrite(buffer);
response.Flush();
}
}
}
示例2: GetFile
public static ActionResult GetFile(HttpResponseBase Response, HttpRequestBase Request, HttpServerUtilityBase Server,
string filePath, string fileName, string contentType, string userFileName)
{
byte[] value;
using (FileStream stream = System.IO.File.Open(filePath, FileMode.Open))
{
value = new byte[stream.Length];
stream.Read(value, 0, (int)stream.Length);
}
//const string userFileName = "MissionOrder.pdf";
//const string contentType = "application/pdf";
Response.Clear();
if (Request.Browser.Browser == "IE")
{
string attachment = String.Format("attachment; filename=\"{0}\"", Server.UrlPathEncode(userFileName));
Response.AddHeader("Content-Disposition", attachment);
}
else
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + userFileName + "\"");
Response.ContentType = contentType;
Response.Charset = "utf-8";
Response.HeaderEncoding = Encoding.UTF8;
Response.ContentEncoding = Encoding.UTF8;
Response.BinaryWrite(value);
Response.End();
return null;
}
示例3: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", FileDownloadName));
byte[] fileContents = Convert.FromBase64String(_base64);
response.BinaryWrite(fileContents);
response.End();
}
示例4: CreateFileResponse
private void CreateFileResponse(HttpResponseBase response, AttachmentDO attachment)
{
var fileData = attachment.Bytes;
response.ContentType = "application/octet-stream";
response.AddHeader("Content-Disposition", "filename=\"" + attachment.OriginalName + "\"");
response.AddHeader("Content-Length", fileData.LongLength.ToString());
response.AddHeader("Content-Type", attachment.Type + "; name=\"" + attachment.OriginalName + "\";");
//Write the data
response.BinaryWrite(fileData);
}
示例5: SetHttpResponse
private void SetHttpResponse(HttpResponseBase httpResponse, string fileNameWithoutExtension, ExcelPackage package)
{
httpResponse.ClearContent();
httpResponse.Buffer = true;
//Write it back to the client
httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
httpResponse.AddHeader("content-disposition", string.Format("attachment; filename={0}.xlsx", fileNameWithoutExtension));
httpResponse.BinaryWrite(package.GetAsByteArray());
httpResponse.Flush();
httpResponse.End();
}
示例6: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
//
string filePath = HostingEnvironment.MapPath("~/Videos/" + FileName);
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
FileStream stream = file.OpenRead();
byte[] videostream = new byte[stream.Length];
stream.Read(videostream, 0, (int)file.Length);
response.BinaryWrite(videostream);
}
else
{
throw new ArgumentException("檔案不存在。", "fileName");
}
}
示例7: SendContent
public bool SendContent(string url, HttpResponseBase response)
{
if (FileStore.SendContent(url, response))
return true;
var key = uriBuilder.ParseKey(url);
var id = Hasher.Hash(uriBuilder.ParseFileName(url));
var file = repository.SingleOrDefault<RequestReduceFile>(id);
if(file != null)
{
response.BinaryWrite(file.Content);
try
{
FileStore.Save(file.Content, url, null);
}
catch(Exception ex)
{
var message = string.Format("could not save {0}", url);
var wrappedException =
new ApplicationException(message, ex);
RRTracer.Trace(message);
RRTracer.Trace(ex.ToString());
if (Registry.CaptureErrorAction != null)
Registry.CaptureErrorAction(wrappedException);
}
RRTracer.Trace("{0} transmitted from db.", url);
if (file.IsExpired)
reductionRepository.RemoveReduction(key);
return true;
}
RRTracer.Trace("{0} not found on file or db.", url);
reductionRepository.RemoveReduction(key);
return false;
}
示例8: CreateCheckCodeImage
private void CreateCheckCodeImage(string checkCode, HttpResponseBase response)
{
if (checkCode == null || checkCode.Trim() == String.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 16.5)), 35);
Graphics g = Graphics.FromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
// Pen drawPen = new Pen(Color.Blue);
// 添加多种颜色 hooyes
Color[] colors = { Color.Blue,Color.Silver,Color.SlateGray,Color.Turquoise,Color.Violet,Color.Turquoise,Color.Tomato,Color.Thistle,Color.Teal,Color.SteelBlue };
//画图片的背景噪音线
for (int i = 0; i < 9; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
Pen drawPen2 = new Pen(colors[i]);
g.DrawLine(drawPen2, x1, y1, x2, y2);
}
// drawPen.Dispose(); Tahoma
Font font = new System.Drawing.Font("Arial", 13, (System.Drawing.FontStyle.Bold));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.Gray, 1.2f, true);
g.DrawString(checkCode, font, brush, 2, 1);
// g.DrawString("J", font, brush, 1, 115);
font.Dispose();
brush.Dispose();
//画图片的前景噪音点
for (int i = 0; i < 20; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(0x8b, 0x8b, 0x8b));
}
//画图片的边框线
Pen borderPen = new Pen(Color.Transparent);
g.DrawRectangle(borderPen, 0, 0, image.Width - 1, image.Height - 1);
borderPen.Dispose();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] buffer = ms.ToArray();
ms.Dispose();
response.ClearContent();
response.ContentType = "image/bmp";
response.BinaryWrite(buffer);
}
finally
{
g.Dispose();
image.Dispose();
}
}
示例9: ExportPdf
public static void ExportPdf(ExportEventArgs options, HttpResponseBase response)
{
response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}.pdf", options.Title));
response.ContentType = "application/pdf";
response.BinaryWrite(ExportPdfHelper.ToPdfBytes(options));
}
示例10: ReceivePack
private void ReceivePack(ControllerContext context, Stream input, HttpResponseBase response)
{
var capabilities = new HashSet<string>(Capabilities.Split(' '));
var requests = ProtocolUtils.ParseUpdateRequests(input, capabilities).ToList();
if (requests.Count == 0)
{
response.BinaryWrite(ProtocolUtils.EndMarker);
return;
}
var reportStatus = capabilities.Contains("report-status");
var useSideBand = capabilities.Contains("side-band-64k");
var reportBand = useSideBand ? ProtocolUtils.PrimaryBand : (int?)null;
var failureBand = reportStatus ? reportBand : ProtocolUtils.ErrorBand;
try
{
ProtocolUtils.UpdateRequest source;
ProtocolUtils.UpdateRequest destination;
var errors = ReadRequests(requests, out source, out destination);
if (errors.Any(e => e.Value != null) || source == null || destination == null)
{
if (reportStatus || useSideBand)
{
ReportFailure(response, failureBand, errors, "expected source and destination branches to be pushed");
}
return;
}
var refPrefix = Guid.NewGuid().ToString();
source = new ProtocolUtils.UpdateRequest(
source.SourceIdentifier,
source.TargetIdentifier,
RepoFormat.FormatSourceRef(refPrefix, 1));
destination = new ProtocolUtils.UpdateRequest(
destination.SourceIdentifier,
destination.TargetIdentifier,
RepoFormat.FormatDestinationRef(refPrefix, 1));
var output = this.ReadPack(new[] { source, destination }, capabilities, input);
var line = ProtocolUtils.ReadPacketLine(output).TrimEnd('\n');
if (line != "unpack ok")
{
line = line.Substring("unpack ".Length);
if (reportStatus || useSideBand)
{
ReportFailure(response, failureBand, errors, line);
}
return;
}
string id;
try
{
using (var ctx = new ReviewContext())
{
using (new NoSyncScope())
{
id = ctx.GetNextReviewId().Result;
}
ctx.Reviews.Add(new Review
{
Id = id,
RefPrefix = refPrefix,
});
ctx.SaveChanges();
}
}
catch (DbUpdateException ex)
{
ReportFailure(response, failureBand, errors, ex.GetBaseException().Message);
throw;
}
if (useSideBand)
{
var url = new UrlHelper(context.RequestContext).Action("Index", "Home", null, context.HttpContext.Request.Url.Scheme) + "#/" + id;
var message = string.Format("code review created:\n\n\t{0}\n\n", url);
response.BinaryWrite(ProtocolUtils.Band(ProtocolUtils.MessageBand, Encoding.UTF8.GetBytes(message)));
}
if (reportStatus)
{
ReportSuccess(response, reportBand);
}
}
finally
{
if (useSideBand)
{
response.BinaryWrite(ProtocolUtils.EndMarker);
}
}
}
示例11: CreateExcel
//.........这里部分代码省略.........
cell = row.CreateCell(16);
cell.CellStyle = cellStyle;
cell.SetCellValue("评语");
//根据答卷
//表格添加内容
List<MODEL.T_InterviewerInfo> list
= OperateContext.Current.BLLSession
.IInterviewerInfoBLL.GetListBy(i => idArr.Contains(i.ID)).ToList();
for (int i = 0; i < list.Count; i++)
{
row = sheet.CreateRow(i + 1);
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].ID);
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].Num);
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].Name);
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].Gender);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].Academy);
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].Major);
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].Class);
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].QQ);
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].Email);
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].TelNum);
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].LearningExperience);
cell = row.CreateCell(11);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].SelfEvaluation);
cell = row.CreateCell(12);
cell.CellStyle = cellStyle;
cell.SetCellValue(list[i].IsRequestTech == true ? "是" : "否");
cell = row.CreateCell(13);
cell.CellStyle = cellStyle;
cell.SetCellValue(GetChoiceScore(list[i].ID));
cell = row.CreateCell(14);
cell.CellStyle = cellStyle;
cell.SetCellValue(GetBriefScore(list[i].ID));
cell = row.CreateCell(15);
cell.CellStyle = cellStyle;
cell.SetCellValue(GetTotalScore(list[i].ID));
cell = row.CreateCell(16);
cell.CellStyle = cellStyle;
cell.SetCellValue(GetComment(list[i].ID));
}
// 设置行宽度
sheet.SetColumnWidth(1, 18 * 256);
sheet.SetColumnWidth(4, 22 * 256);
sheet.SetColumnWidth(5, 22 * 256);
sheet.SetColumnWidth(7, 15 * 256);
sheet.SetColumnWidth(8, 21 * 256);
sheet.SetColumnWidth(9, 16 * 256);
sheet.SetColumnWidth(12, 18 * 256);
sheet.SetColumnWidth(16, 30 * 256);
//将Excel内容写入到流中
MemoryStream file = new MemoryStream();
excel.Write(file);
//输出
response.BinaryWrite(file.GetBuffer());
response.End();
}
示例12: CreateValidateGraphic
/// <summary>
/// 创建验证码的图片
/// </summary>
/// <param name="containsPage">要输出到的page对象</param>
/// <param name="validateNum">验证码</param>
public void CreateValidateGraphic(string validateCode,HttpResponseBase Response)
{
Bitmap image = new Bitmap((int)Math.Ceiling(validateCode.Length * 12.0), 22);
Graphics g = Graphics.FromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的干扰线
for (int i = 0; i < 25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
Font font = new Font("Arial", 12, (FontStyle.Bold | FontStyle.Italic));
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height),
Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(validateCode, font, brush, 3, 2);
//画图片的前景干扰点
for (int i = 0; i < 100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
//保存图片数据
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Jpeg);
//输出图片流
Response.Clear();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(stream.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
示例13: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.BinaryWrite(CreateCalendarBytes());
}
示例14: WriteResponse
public void WriteResponse(HttpResponseBase response)
{
response.ThrowIfNull("response");
response.StatusCode = _statusCode.StatusCode;
response.SubStatusCode = _statusCode.SubStatusCode;
response.ContentType = ContentType;
response.Charset = Charset;
response.ContentEncoding = ContentEncoding;
foreach (Header header in Headers)
{
response.Headers.Add(header.Field, header.Value);
}
response.HeaderEncoding = HeaderEncoding;
foreach (Cookie cookie in Cookies)
{
response.Cookies.Add(cookie.GetHttpCookie());
}
_cachePolicy.Apply(response.Cache);
response.BinaryWrite(_content);
}
示例15: WriteResponseAsync
public async Task WriteResponseAsync(HttpResponseBase response)
{
response.ThrowIfNull("response");
response.StatusCode = _statusCode.StatusCode;
response.SubStatusCode = _statusCode.SubStatusCode;
response.ContentType = ContentType;
response.Charset = Charset;
response.ContentEncoding = ContentEncoding;
foreach (Header header in Headers)
{
response.Headers.Add(header.Field, header.Value);
}
response.HeaderEncoding = HeaderEncoding;
foreach (Cookie cookie in Cookies)
{
response.Cookies.Add(cookie.GetHttpCookie());
}
_cachePolicy.Apply(response.Cache);
response.TrySkipIisCustomErrors = _skipIisCustomErrors;
response.BinaryWrite(await _content.Value);
}