本文整理汇总了C#中WebClient.OpenWrite方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.OpenWrite方法的具体用法?C# WebClient.OpenWrite怎么用?C# WebClient.OpenWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebClient
的用法示例。
在下文中一共展示了WebClient.OpenWrite方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteHtml
/// <summary>
/// 写页面
/// </summary>
public static void WriteHtml()
{
WebClient client = new WebClient();
Stream stream = client.OpenWrite("E:/XBoom/GodWay/GodWay1/Web/Log/newfile.txt","PUT");
StreamWriter streamWrite = new StreamWriter(stream);
streamWrite.WriteLine("Hello World");
streamWrite.Close();
}
示例2: OpenWriteAsync
protected override Task<Stream> OpenWriteAsync(WebClient wc, string address) => Task.Run(() => wc.OpenWrite(address));
示例3: OpenWrite_InvalidArguments_ThrowExceptions
public static void OpenWrite_InvalidArguments_ThrowExceptions()
{
var wc = new WebClient();
Assert.Throws<ArgumentNullException>("address", () => { wc.OpenWrite((string)null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.OpenWrite((string)null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.OpenWrite((Uri)null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.OpenWrite((Uri)null, null); });
}
示例4: UpLoadFile
public bool UpLoadFile(string fileNameFullPath, string strUrlDirPath)
{
string str = fileNameFullPath.Substring(fileNameFullPath.LastIndexOf(@"\") + 1);
string str2 = DateTime.Now.ToString("yyyyMMddhhmmss") + DateTime.Now.Millisecond.ToString() + fileNameFullPath.Substring(fileNameFullPath.LastIndexOf("."));
str.Substring(str.LastIndexOf(".") + 1);
if (!strUrlDirPath.EndsWith("/"))
{
strUrlDirPath = strUrlDirPath + "/";
}
if (Directory.Exists(base.Server.MapPath(strUrlDirPath)))
{
Directory.CreateDirectory(base.Server.MapPath(strUrlDirPath));
}
strUrlDirPath = strUrlDirPath + str2;
WebClient client = new WebClient
{
Credentials = CredentialCache.DefaultCredentials
};
FileStream input = new FileStream(fileNameFullPath, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(input);
try
{
byte[] buffer = reader.ReadBytes((int)input.Length);
Stream stream2 = client.OpenWrite(strUrlDirPath, "PUT");
if (stream2.CanWrite)
{
stream2.Write(buffer, 0, buffer.Length);
}
stream2.Close();
return true;
}
catch (Exception)
{
return false;
}
}