本文整理汇总了C#中System.Net.Mime.ContentDisposition类的典型用法代码示例。如果您正苦于以下问题:C# ContentDisposition类的具体用法?C# ContentDisposition怎么用?C# ContentDisposition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContentDisposition类属于System.Net.Mime命名空间,在下文中一共展示了ContentDisposition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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);
}
示例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();
}
示例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));
}
示例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");
}
示例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;
}
}
示例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;
}
示例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 ());
}
示例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");
}
示例11: UploadedFile
public UploadedFile(string filename,
ContentType contentType,
ContentDisposition contentDisposition,
string tempFilename)
{
ContentDisposition = contentDisposition;
ContentType = contentType;
Filename = filename;
_tempFilename = tempFilename;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}