本文整理汇总了C#中System.Net.Mime.ContentDisposition类的典型用法代码示例。如果您正苦于以下问题:C# ContentDisposition类的具体用法?C# ContentDisposition怎么用?C# ContentDisposition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContentDisposition类属于System.Net.Mime命名空间,在下文中一共展示了ContentDisposition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DownloadFile
/// <summary>
/// Downloads a single file synchronously
/// </summary>
/// <param name="url">The URL to download the file from (either a fully qualified URL or an app relative/absolute path)</param>
/// <param name="sendAuthCookie">Specifies whether the FormsAuthenticationCookie should be sent</param>
/// <param name="timeout">Timeout in milliseconds</param>
public FileDownloadResponse DownloadFile(string url, bool sendAuthCookie = false, int? timeout = null)
{
Guard.ArgumentNotEmpty(() => url);
url = WebHelper.GetAbsoluteUrl(url, _httpRequest);
var req = (HttpWebRequest)WebRequest.Create(url);
req.UserAgent = "SmartStore.NET";
if (timeout.HasValue)
{
req.Timeout = timeout.Value;
}
if (sendAuthCookie)
{
req.SetFormsAuthenticationCookie(_httpRequest);
}
using (var resp = (HttpWebResponse)req.GetResponse())
{
using (var stream = resp.GetResponseStream())
{
if (resp.StatusCode == HttpStatusCode.OK)
{
var data = stream.ToByteArray();
var cd = new ContentDisposition(resp.Headers["Content-Disposition"]);
var fileName = cd.FileName;
return new FileDownloadResponse(data, fileName, resp.ContentType);
}
}
}
return null;
}
开发者ID:mandocaesar,项目名称:Mesinku,代码行数:41,代码来源:FileDownloadManager.cs
示例2: 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);
}
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:7,代码来源:CertificateController.cs
示例3: GetFileName
private static string GetFileName(ContentDisposition contentDisposition)
{
if (contentDisposition.FileName != null)
{
return contentDisposition.FileName;
}
var fileName = contentDisposition.Parameters["filename*"];
if (fileName == null)
{
return null;
}
var pos = fileName.IndexOf("''", StringComparison.InvariantCulture);
var encoding = Encoding.UTF8;
if (pos >= 0)
{
try
{
encoding = Encoding.GetEncoding(fileName.Substring(0, pos));
}
catch (ArgumentException)
{
}
fileName = fileName.Substring(pos + 2);
}
return HttpUtility.UrlDecode(fileName, encoding);
}
开发者ID:Saleslogix,项目名称:SDataCSharpClientLib,代码行数:29,代码来源:AttachedFile.cs
示例4: 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();
}
开发者ID:vipwan,项目名称:CommunityServer,代码行数:27,代码来源:ContentDispositionUtil.cs
示例5: Equals
public void Equals ()
{
ContentDisposition dummy1 = new ContentDisposition ();
dummy1.FileName = "genome.jpeg";
ContentDisposition dummy2 = new ContentDisposition ("attachment; filename=genome.jpeg");
Assert.IsTrue (dummy1.Equals (dummy2));
}
开发者ID:popekim,项目名称:mono,代码行数:7,代码来源:ContentDispositionTest.cs
示例6: 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");
}
开发者ID:nampn,项目名称:ODental,代码行数:25,代码来源:MedicalController.cs
示例7: DownloadBloodcatSet
public void DownloadBloodcatSet(string setID)
{
if (alreadyDownloading)
{
MessageBox.Show("Already downloading a beatmap. Parallel downloads are currently not supported, sorry :(");
return;
}
form1.progressBar1.Visible = true;
form1.button1.Enabled = false;
alreadyDownloading = true;
var downloadURL = "http://bloodcat.com/osu/s/" + setID;
// https://stackoverflow.com/questions/13201059/howto-download-a-file-keeping-the-original-name-in-c
// Get file name of beatmap (and test if its even valid)
var request = WebRequest.Create(downloadURL);
try
{
var response = request.GetResponse();
ContentDisposition contentDisposition = new ContentDisposition(response.Headers["Content-Disposition"]); // using .net's mime.contentdisposition class
originalFileName = contentDisposition.FileName.ToString();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(dlProgressHandler);
client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(dlCompleteHandler);
client.DownloadFileAsync(new Uri(downloadURL), Path.Combine(Application.StartupPath, originalFileName + ".partial"));
// Download to a temp folder (program's folder) because if osu! detects semi downloaded it map it calls it corrupt and deletes/moves it ;-;
}
catch (Exception e)
{
MessageBox.Show("Invalid beatmap... maybe bloodcat doesn't have it, or you put in an invalid ID (in which case you are a jerk)?");
form1.progressBar1.Visible = false;
form1.dataGridView1.Enabled = true;
alreadyDownloading = false;
}
}
开发者ID:nicholastay,项目名称:NexDirect-old,代码行数:35,代码来源:WebOps.cs
示例8: GetTemplate
internal static ProvisioningTemplate GetTemplate(Guid templateId)
{
HttpContentHeaders headers = null;
// Get the template via HTTP REST
var templateStream = HttpHelper.MakeGetRequestForStreamWithResponseHeaders($"{BaseTemplateGalleryUrl}/api/DownloadTemplate?templateId={templateId}", "application/octet-stream", out headers);
// If we have any result
if (templateStream != null)
{
XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(templateStream));
var cd = new ContentDisposition(headers.ContentDisposition.ToString());
var openXMLFileName = cd.FileName;
// Determine the name of the XML file inside the PNP Open XML file
var xmlTemplateFile = openXMLFileName.ToLower().Replace(".pnp", ".xml");
// Get the template
var result = provider.GetTemplate(xmlTemplateFile);
result.Connector = provider.Connector;
templateStream.Close();
return result;
}
return null;
}
开发者ID:OfficeDev,项目名称:PnP-PowerShell,代码行数:25,代码来源:GalleryHelper.cs
示例9: EqualsHashCode
public void EqualsHashCode ()
{
ContentDisposition dummy1 = new ContentDisposition ();
dummy1.Inline = true;
ContentDisposition dummy2 = new ContentDisposition ("inline");
Assert.IsTrue (dummy1.Equals (dummy2));
Assert.IsFalse (dummy1 == dummy2);
Assert.IsTrue (dummy1.GetHashCode () == dummy2.GetHashCode ());
}
开发者ID:popekim,项目名称:mono,代码行数:9,代码来源:ContentDispositionTest.cs
示例10: 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");
}
开发者ID:r3plica,项目名称:Boomerang,代码行数:10,代码来源:CommonController.cs
示例11: UploadedFile
public UploadedFile(string filename,
ContentType contentType,
ContentDisposition contentDisposition,
string tempFilename)
{
ContentDisposition = contentDisposition;
ContentType = contentType;
Filename = filename;
_tempFilename = tempFilename;
}
开发者ID:chakrit,项目名称:fu-sharp,代码行数:11,代码来源:UploadedFile.cs
示例12: SerializableContentDisposition
public SerializableContentDisposition(ContentDisposition contentDisposition)
{
CreationDate = contentDisposition.CreationDate;
DispositionType = contentDisposition.DispositionType;
FileName = contentDisposition.FileName;
Inline = contentDisposition.Inline;
ModificationDate = contentDisposition.ModificationDate;
Parameters = new SerializableCollection(contentDisposition.Parameters);
ReadDate = contentDisposition.ReadDate;
Size = contentDisposition.Size;
}
开发者ID:nutrija,项目名称:revenj,代码行数:11,代码来源:SerializableContentDisposition.cs
示例13: SerializableContentDisposition
private SerializableContentDisposition(ContentDisposition disposition) {
CreationDate = disposition.CreationDate;
DispositionType = disposition.DispositionType;
FileName = disposition.FileName;
Inline = disposition.Inline;
ModificationDate = disposition.ModificationDate;
Parameters = new StringDictionary();
foreach (string k in disposition.Parameters.Keys)
Parameters.Add(k, disposition.Parameters[k]);
ReadDate = disposition.ReadDate;
Size = disposition.Size;
}
开发者ID:sadiqna,项目名称:TicketDesk,代码行数:12,代码来源:SerializableContentDisposition.cs
示例14: GetFileName
private static string GetFileName(HttpWebResponse response)
{
var contentDisposition = response.Headers["Content-Disposition"];
if (contentDisposition.IsNullOrEmpty())
return null;
var disposition = new ContentDisposition(contentDisposition);
if (disposition.FileName.IsNullOrEmpty())
return null;
return disposition.FileName;
}
开发者ID:ashmind,项目名称:lightget,代码行数:12,代码来源:Downloader.cs
示例15: CopyTo
public void CopyTo(ContentDisposition contentDisposition)
{
contentDisposition.CreationDate = CreationDate;
contentDisposition.DispositionType = DispositionType;
contentDisposition.FileName = FileName;
contentDisposition.Inline = Inline;
contentDisposition.ModificationDate = ModificationDate;
contentDisposition.ReadDate = ReadDate;
contentDisposition.Size = Size;
Parameters.CopyTo(contentDisposition.Parameters);
}
开发者ID:nutrija,项目名称:revenj,代码行数:12,代码来源:SerializableContentDisposition.cs
示例16: SetContentDisposition
internal void SetContentDisposition(ContentDisposition scd)
{
scd.CreationDate = CreationDate;
scd.DispositionType = DispositionType;
scd.FileName = FileName;
scd.Inline = Inline;
scd.ModificationDate = ModificationDate;
Parameters.SetColletion(scd.Parameters);
scd.ReadDate = ReadDate;
scd.Size = Size;
}
开发者ID:endeavour,项目名称:town-crier,代码行数:12,代码来源:SerializeableContentDisposition.cs
示例17: 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");
}
开发者ID:ProAFSolutions,项目名称:PDFGenerator,代码行数:14,代码来源:PdfController.cs
示例18: GetHeaderValue
public static string GetHeaderValue(string fileName)
{
try
{
ContentDisposition disposition = new ContentDisposition
{
FileName = fileName
};
return disposition.ToString();
}
catch (FormatException)
{
return CreateRfc2231HeaderValue(fileName);
}
}
开发者ID:Epitomy,项目名称:CMS,代码行数:15,代码来源:HttpResponseExtensions.cs
示例19: 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");
}
开发者ID:hendrikmaarand,项目名称:vso.io,代码行数:15,代码来源:StaticController.cs
示例20: 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))
{
string str = new ContentDisposition { FileName = this.FileDownloadName, Inline = Inline }.ToString();
context.HttpContext.Response.AddHeader("Content-Disposition", str);
}
WriteFile(response);
}
开发者ID:allanjohny,项目名称:SGAL,代码行数:16,代码来源:CustomFileResult.cs
注:本文中的System.Net.Mime.ContentDisposition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论