本文整理汇总了C#中System.IO.FileStream.WriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream.WriteAsync方法的具体用法?C# System.IO.FileStream.WriteAsync怎么用?C# System.IO.FileStream.WriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了System.IO.FileStream.WriteAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
public async Task<IHttpActionResult> Post()
{
if (!Request.Content.IsMimeMultipartContent())
{
return BadRequest();
}
var provider = new MultipartMemoryStreamProvider();
// путь к папке на сервере
string root = System.Web.HttpContext.Current.Server.MapPath("~/UploadedFiles/");
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var file in provider.Contents)
{
var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
byte[] fileArray = await file.ReadAsByteArrayAsync();
using (System.IO.FileStream fs = new System.IO.FileStream(root + filename, System.IO.FileMode.Create))
{
await fs.WriteAsync(fileArray, 0, fileArray.Length);
}
var temp = users.GetById(Convert.ToInt32(User.Identity.Name));
temp.Photo = "UploadedFiles/" + filename;
users.Edit(temp);
}
return Ok("OK");
}
示例2: RunAsync
public async Task RunAsync() {
var apks = CommandRunner.Instance.GetInstalledPackagesApkInformation ( );
this.LogDebug("Initializing APK Cache");
foreach(var item in apks) {
var lvi = new ApkPackageListViewItem(item);
// cant uninstall if we dont know the package
if(string.IsNullOrEmpty(lvi.ApkInformation.Package)) {
continue;
}
string keyName = lvi.ApkInformation.DevicePath;
if(keyName.StartsWith("/")) {
keyName = keyName.Substring(1);
}
keyName = keyName.Replace("/", ".");
if(!Program.SystemIcons.ContainsKey(keyName)) {
// get apk and extract the app icon
var img = CommandRunner.Instance.GetLocalApkIconImage(item.LocalApk);
if(img == null) {
img = DroidExplorer.Resources.Images.package32;
} else {
using(System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
string fileName = System.IO.Path.Combine(System.IO.Path.Combine(CommandRunner.Settings.UserDataDirectory, Cache.APK_IMAGE_CACHE), string.Format("{0}.png", keyName));
img.Save(stream, ImageFormat.Png);
stream.Position = 0;
using(System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
byte[] buffer = new byte[2048];
int readBytes = 0;
while((readBytes = await stream.ReadAsync(buffer, 0, buffer.Length)) != 0) {
await fs.WriteAsync(buffer, 0, readBytes);
}
}
}
}
//SystemImageListHost.Instance.AddFileTypeImage ( keyName, img, img );
}
}
}
示例3: GetCertifyFile
/// <summary>
///
/// </summary>
/// <returns></returns>
public String GetCertifyFile()
{
String result = String.Empty;
// User Data
String userName = "[email protected]";
String password = "password";
String id = "1244eaaa-9cbe-434a-a3eb-762fa8be865f";
// POST Data
var postData = new
{
UserName = userName,
Password = password,
Id = id.ToUpper()
};
// Json Data
var jsonData = JsonConvert.SerializeObject(postData, Formatting.None);
byte[] buffer;
String fileName = String.Format("message_{0}.pdf", id); ;
try
{
// Execute
buffer = this.ExecuteAndDownload(Helper.RestOperations.GetCertifyFile, jsonData, ref fileName);
}
catch(Exception ex)
{
return ex.Message;
}
String fileDirectory = @"C:\SMSCertifies\sms.didimo\";
using (System.IO.FileStream fs = new System.IO.FileStream(System.IO.Path.Combine(fileDirectory, fileName), System.IO.FileMode.OpenOrCreate))
{
fs.WriteAsync(buffer, 0, buffer.Length).Wait();
}
result = String.Format("File saved on {0}", System.IO.Path.Combine(fileDirectory, fileName));
return result;
}
示例4: GetCertifyFile
/// <summary>
///
/// </summary>
/// <returns></returns>
public String GetCertifyFile()
{
String result = String.Empty;
// User Data
String userName = "[email protected]";
String password = "password";
String id = "1244eaaa-9cbe-434a-a3eb-762fa8be865f";
// POST Data
var postData = new
{
UserName = userName,
Password = password,
Id = id.ToUpper()
};
// Xml Data
var xmlData = String.Format(@"
<GetCertifyFileRequest xmlns='https://sms.didimo.es/wcf/GetCertifyFileRequest'>
<UserName>{0}</UserName>
<Password>{1}</Password>
<Id>{2}</Id>
</GetCertifyFileRequest>
", postData.UserName, postData.Password, postData.Id);
byte[] buffer;
String fileName = String.Format("message_{0}.pdf", id); ;
try
{
// Execute
buffer = this.ExecuteAndDownload(Helper.RestOperations.GetCertifyFile, xmlData, ref fileName);
}
catch (Exception ex)
{
return ex.Message;
}
String fileDirectory = @"C:\SMSCertifies\sms.didimo\";
using (System.IO.FileStream fs = new System.IO.FileStream(System.IO.Path.Combine(fileDirectory, fileName), System.IO.FileMode.OpenOrCreate))
{
fs.WriteAsync(buffer, 0, buffer.Length).Wait();
}
result = String.Format("File saved on {0}", System.IO.Path.Combine(fileDirectory, fileName));
return result;
}
示例5: GetCertifyFile
/// <summary>
///
/// </summary>
/// <returns></returns>
public String GetCertifyFile()
{
String result = String.Empty;
// User Data
String userName = "[email protected]";
String password = "password";
String id = "1244eaaa-9cbe-434a-a3eb-762fa8be865f";
// POST Data
var postData = new
{
user = userName,
password = password,
id = id.ToUpper()
};
NameValueCollection parameters = new NameValueCollection();
postData.GetType().GetProperties()
.ToList()
.ForEach(pi => parameters.Add(pi.Name, pi.GetValue(postData, null).ToString()));
byte[] buffer;
String fileName = String.Format("message_{0}.pdf", id); ;
try
{
// Execute
buffer = this.ExecuteAndDownload(Helper.UrlOperations.GetCertifyFile, parameters, ref fileName);
}
catch (Exception ex)
{
return ex.Message;
}
String fileDirectory = @"C:\SMSCertifies\sms.didimo\";
using (System.IO.FileStream fs = new System.IO.FileStream(System.IO.Path.Combine(fileDirectory, fileName), System.IO.FileMode.OpenOrCreate))
{
fs.WriteAsync(buffer, 0, buffer.Length).Wait();
}
result = String.Format("File saved on {0}", System.IO.Path.Combine(fileDirectory, fileName));
return result;
}
示例6: SaveToFile
private async void SaveToFile(string[] fileNames)
{
var filename = fileNames.FirstOrDefault();
if (string.IsNullOrEmpty(filename))
{ return; }
using (var stream = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
var bytes = System.Text.Encoding.UTF8.GetBytes(this.Text);
await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
}
}