本文整理汇总了C#中System.Net.Mime.ContentDisposition.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ContentDisposition.ToString方法的具体用法?C# ContentDisposition.ToString怎么用?C# ContentDisposition.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mime.ContentDisposition
的用法示例。
在下文中一共展示了ContentDisposition.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
public ActionResult Index()
{
var path = HttpContext.Server.MapPath("~\\App_Data\\Kentor.AuthServices.StubIdp.cer");
var disposition = new ContentDisposition { Inline = false, FileName = Path.GetFileName(path) };
Response.AppendHeader("Content-Disposition", disposition.ToString());
return File(path, MediaTypeNames.Text.Plain);
}
示例2: ShowPdfFile
public ActionResult ShowPdfFile(long? d)
{
Documentm doc=null;
long DocNum=0;
if(d!=null) {
DocNum=(long)d;
}
Patientm patm;
if(Session["Patient"]==null) {
return RedirectToAction("Login");
}
else {
patm=(Patientm)Session["Patient"];
}
if(DocNum!=0) {
doc=Documentms.GetOne(patm.CustomerNum,DocNum);
}
if(doc==null || patm.PatNum!=doc.PatNum) {//make sure that the patient does not pass the another DocNum of another patient.
return new EmptyResult(); //return a blank page todo: return page with proper message.
}
ContentDisposition cd = new ContentDisposition();
cd.Inline=true;//the browser will try and show the pdf inline i.e inside the browser window. If set to false it will force a download.
Response.AppendHeader("Content-Disposition",cd.ToString());
return File(Convert.FromBase64String(doc.RawBase64),"application/pdf","Statement.pdf");
}
示例3: GetHeaderValue
public static string GetHeaderValue(string fileName, bool inline = false, bool withoutBase = false)
{
// If fileName contains any Unicode characters, encode according
// to RFC 2231 (with clarifications from RFC 5987)
if (fileName.Any(c => (int)c > 127))
{
var str = withoutBase
? "{0}; filename*=UTF-8''{2}"
: "{0}; filename=\"{1}\"; filename*=UTF-8''{2}";
return string.Format(str,
inline ? "inline" : "attachment",
fileName,
CreateRfc2231HeaderValue(fileName));
}
// Knowing there are no Unicode characters in this fileName, rely on
// ContentDisposition.ToString() to encode properly.
// In .Net 4.0, ContentDisposition.ToString() throws FormatException if
// the file name contains Unicode characters.
// In .Net 4.5, ContentDisposition.ToString() no longer throws FormatException
// if it contains Unicode, and it will not encode Unicode as we require here.
// The Unicode test above is identical to the 4.0 FormatException test,
// allowing this helper to give the same results in 4.0 and 4.5.
var disposition = new ContentDisposition { FileName = fileName, Inline = inline };
return disposition.ToString();
}
示例4: Export
public ActionResult Export(string FileContent, string FileName)
{
var cd = new ContentDisposition
{
FileName = FileName + ".csv",
Inline = false
};
Response.AddHeader("Content-Disposition", cd.ToString());
return Content(FileContent, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
示例5: GeneratePDF
public ActionResult GeneratePDF()
{
var url = "http://www.google.com";
byte[] pdfBuf = PDFHelper.ConvertToPdf(PDFHelper.DataType.URL, url, "DocumentTitle");
var cd = new ContentDisposition
{
FileName = "DocName.pdf",
Inline = false // always prompt the user for downloading, set to true if you want the browser to try to show the file inline
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(pdfBuf, "application/pdf");
}
示例6: DownloadExtension
public ActionResult DownloadExtension()
{
string path = AppDomain.CurrentDomain.BaseDirectory + "/vss-extension.json";
byte[] data = System.IO.File.ReadAllBytes(path);
var header = new ContentDisposition
{
FileName = "vss-extension.json",
Inline = false
};
Response.AppendHeader("Content-Disposition", header.ToString());
return File(data, "application/force-download");
}
示例7: GetHeaderValue
public static string GetHeaderValue(string fileName)
{
try
{
ContentDisposition disposition = new ContentDisposition
{
FileName = fileName
};
return disposition.ToString();
}
catch (FormatException)
{
return CreateRfc2231HeaderValue(fileName);
}
}
示例8: GetHeaderValue
protected string GetHeaderValue(string fileName)
{
try
{
ContentDisposition contentDisposition = new ContentDisposition
{
FileName = fileName,
Inline = Inline
};
return contentDisposition.ToString();
}
catch (FormatException ex)
{
return "FormatException";
}
}
示例9: InstallerBatchFile
//public ActionResult Install()
//{
// return File(Url.Content("~/installChocolatey.ps1"), "text/plain");
//}
public FileResult InstallerBatchFile()
{
const string batchFile = @"@echo off
SET DIR=%~dp0%
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ""((new-object net.webclient).DownloadFile('https://chocolatey.org/install.ps1','install.ps1'))""
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ""& '%DIR%install.ps1' %*""
SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin";
var contentDisposition = new ContentDisposition
{
FileName = "installChocolatey.cmd",
Inline = true,
};
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
return File(Encoding.ASCII.GetBytes(batchFile), "text/plain");
}
示例10: ProcessRequest
public override void ProcessRequest(HttpContext context)
{
if (!BXPrincipal.Current.IsCanOperate("UpdateSystem"))
{
BXAuthentication.AuthenticationRequired();
return;
}
if (context.Request.QueryString["original"] != null)
{
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition();
cd.FileName = "web.config";
context.Response.ContentType = "application/x-octet-stream";
context.Response.AddHeader("Content-Disposition", cd.ToString());
context.Response.TransmitFile(HostingEnvironment.MapPath("~/web.config"));
return;
}
if (context.Request.QueryString["convert4"] != null)
{
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition();
cd.FileName = "web.config";
context.Response.ContentType = "application/x-octet-stream";
context.Response.AddHeader("Content-Disposition", cd.ToString());
context.Response.ContentEncoding = Encoding.UTF8;
XmlWriterSettings ws = new XmlWriterSettings();
ws.Indent = true;
ws.IndentChars = "\t";
ws.Encoding = Encoding.UTF8;
using (XmlWriter xml = XmlWriter.Create(context.Response.OutputStream, ws))
{
MakeConfig(xml);
}
context.Response.End();
return;
}
base.ProcessRequest(context);
}
示例11: WriteResponse
public static void WriteResponse(HttpResponse response, byte[] filearray, string type)
{
response.ClearContent();
response.Buffer = true;
response.Cache.SetCacheability(HttpCacheability.Private);
response.ContentType = "application/pdf";
ContentDisposition contentDisposition = new ContentDisposition();
contentDisposition.FileName = "SaldoDotacao.pdf";
contentDisposition.DispositionType = type;
response.AddHeader("Content-Disposition", contentDisposition.ToString());
response.BinaryWrite(filearray);
HttpContext.Current.ApplicationInstance.CompleteRequest();
try
{
response.End();
}
catch (System.Threading.ThreadAbortException)
{
}
}
示例12: Index
public ActionResult Index(string filename, string ext)
{
if (string.IsNullOrEmpty(filename) || string.IsNullOrEmpty(ext)) return HttpNotFound();
filename = filename + "." + ext;
Document document = ReaderFactory.GetDocumentReader().GetDocument(filename);
if (document == null)
{
return HttpNotFound();
}
var cd = new ContentDisposition
{
FileName = document.FileName,
Inline = false,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
var contentType = GetContentType(document.FileName);
return File(document.FileData, contentType);
}
示例13: ExecuteResult
public override void ExecuteResult(ControllerContext context) {
if (context == null) {
throw new ArgumentNullException("context");
}
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = ContentType;
if (!String.IsNullOrEmpty(FileDownloadName)) {
// From RFC 2183, Sec. 2.3:
// The sender may want to suggest a filename to be used if the entity is
// detached and stored in a separate file. If the receiving MUA writes
// the entity to a file, the suggested filename should be used as a
// basis for the actual filename, where possible.
ContentDisposition disposition = new ContentDisposition() { FileName = FileDownloadName };
string headerValue = disposition.ToString();
context.HttpContext.Response.AddHeader("Content-Disposition", headerValue);
}
WriteFile(response);
}
示例14: DownloadFile
/// <summary>
/// Downloads the protocol with the given id as a pdf-file or returns the user
/// to the view with the table of info about meeting protocols if something went wrong.
/// </summary>
/// <param name="id">The id of the meeting protocol-file to download.</param>
/// <returns>redirects the user to the table with info about meeting protcols
/// if something went wrong, otherwise returns a file-download-prompt.</returns>
/// <exception cref="ArgumentException">Thrown if the method is called without an id.</exception>
public ActionResult DownloadFile(int? id)
{
//if no id is provided, an exception is thrown.
if (!id.HasValue)
{
throw new ArgumentException("id must be provided!");
}
LgProtocolModel model;
//Fetches info about the meeting protocol based on its id from the database .
using (IProtocolRepository repository = new ProtocolRepository())
{
model = repository.GetLgProtocolById(id.Value);
}
//Gets the original file name from the model with info fetched from the database
string fileName = model.Name + ".pdf";
//Gets the path to the file on the server.
string filePath = Server.MapPath("~/App_Data/LgProtocols") + "/" + model.NameOnServer;
try
{
//Loads the file i´nto memory.
byte[] fileData = System.IO.File.ReadAllBytes(filePath);
//Gets the extension of the file based on the mimetype.
string contentType = MimeMapping.GetMimeMapping(".pdf");
/*Creates a contentdisposition header and appends it to the http-response.
It is needed for a download prompt to be generated.*/
var contentDisposition = new ContentDisposition
{
FileName = fileName,
Inline = false
};
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
return File(fileData, contentType);
}
catch
{
//if an error occured return teh user tot he view with the table of info abóut meeting protocols.
return RedirectToAction("Index");
}
}
示例15: DownloadImageTemplate
public async virtual Task<ActionResult> DownloadImageTemplate(string imageTemplatePath)
{
var encryptor = new DPAPIEncryptor();
var uriString = encryptor.Decrypt(imageTemplatePath);
var uri = new Uri(uriString, UriKind.Absolute);
var contentDisposition = new ContentDisposition()
{
FileName = uri.Segments.Last(),
Inline = false,
};
var webClient = new WebClient();
webClient.UseDefaultCredentials = true;
var fileData = await webClient.DownloadDataTaskAsync(uri);
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
return File(fileData, "image/png");
}