本文整理汇总了C#中IFile.OpenStream方法的典型用法代码示例。如果您正苦于以下问题:C# IFile.OpenStream方法的具体用法?C# IFile.OpenStream怎么用?C# IFile.OpenStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFile
的用法示例。
在下文中一共展示了IFile.OpenStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
public OperationResult Post(IFile file)
{
return new OperationResult.SeeOther
{
RedirectLocation = typeof(UploadedFile).CreateUri(new { id = this.ReceiveStream(file.ContentType, file.OpenStream()) })
};
}
示例2: Post
// "id" is issue ID
public object Post(int id, AddAttachmentArgs args, IFile attachment = null)
{
return ExecuteInUnitOfWork(() =>
{
Issue issue = IssueRepository.Get(id);
Attachment att;
if (attachment != null)
{
using (Stream s = attachment.OpenStream())
{
byte[] content = s.ReadAllBytes();
att = new Attachment(issue, args.Title, args.Description, content, attachment.ContentType.MediaType);
}
}
else
{
att = new Attachment(issue, args.Title, args.Description, null, null);
}
AttachmentRepository.Add(att);
Uri attUrl = typeof(AttachmentResource).CreateUri(new { id = att.Id });
return new OperationResult.Created { RedirectLocation = attUrl };
});
}
示例3: File
public void File(IFile file, string name)
{
string contentType = "";
string filename = Path.GetFileName(file.Filename ?? "unknown");
string asciiFilename = Regex.Replace(filename, @"[^\u0000-\u007F]", "x");
string filenameFormat = string.Format("; filename=\"{0}\"", asciiFilename);
if (asciiFilename != filename && Settings != null && Settings.EnableNonAsciiCharactersInMultipartFilenames)
{
string utf8Filename = HttpUtility.UrlEncode(filename, Encoding.UTF8);
filenameFormat += string.Format("; filename*=UTF-8''{0}", utf8Filename);
}
if (file.ContentType != null)
contentType = string.Format("\r\nContent-Type: {0}", file.ContentType);
string header = string.Format(@"
--{0}
Content-Disposition: form-data; name=""{1}""{2}{3}
", Boundary, name, filenameFormat, contentType);
// FIXME: escaping name and filename
Writer.Write(header);
Writer.Flush();
using (Stream s = file.OpenStream())
{
s.CopyTo(Output);
}
}
示例4: Post
public OperationResult Post(DocumentInfo doc, IFile sentFile)
{
doc.Id = Database.Documents.Max(x => x.Id) + 1;
doc.FileName = sentFile.FileName;
using (var reader = new BinaryReader(sentFile.OpenStream()))
doc.Data = reader.ReadBytes((int)sentFile.Length);
doc.LastModifiedTimeUTC = DateTime.UtcNow;
doc.DataHref = new DocumentData { Id = doc.Id }.CreateUri();
var createdUri = doc.CreateUri();
Database.Documents.Add(doc);
return new OperationResult.Created
{
RedirectLocation = createdUri,
ResponseResource = "Document created at " + createdUri
};
}
示例5: Post
public object Post(int id, UpdateAttachmentArgs args, IFile attachment = null)
{
return ExecuteInUnitOfWork(() =>
{
Attachment a = AttachmentRepository.Get(id);
if (attachment == null)
a.Update(args.Title, args.Description);
else
{
// Kick NHibernate in the b*lls to make sure lazy loaded property is loaded and updated
byte[] dummy = a.Content;
using (Stream s = attachment.OpenStream())
{
byte[] content = s.ReadAllBytes();
a.Update(args.Title, args.Description, content, attachment.ContentType.ToString());
}
}
return ReadAttachmentResource(id);
});
}
示例6: Post
// "id" is project ID
public object Post(int id, AddIssueArgs args, IFile attachment = null)
{
return ExecuteInUnitOfWork(() =>
{
Project p = ProjectRepository.Get(id);
Issue i = new Issue(p, args.Title, args.Description, args.Severity);
IssueRepository.Add(i);
if (args.Attachment != null && attachment != null)
{
using (Stream s = attachment.OpenStream())
{
byte[] content = s.ReadAllBytes();
Attachment att = new Attachment(i, args.Attachment.Title, args.Attachment.Description, content, attachment.ContentType.MediaType);
AttachmentRepository.Add(att);
}
}
Uri issueUrl = typeof(IssueResource).CreateUri(new { id = i.Id });
return new OperationResult.Created { RedirectLocation = issueUrl };
});
}