fileURL:上传文件的路地址
docfile:byte[]类型的字节流
private void UploadToLibrary(string fileURL, byte[] docfile)
{
WebRequest request = WebRequest.Create(fileURL);
request.Credentials = System.Net.NetworkCredential(ConfigurationManager.AppSettings["UserName"],
ConfigurationManager.AppSettings["UserPassword"], ConfigurationManager.AppSettings["Domain"]);
request.Method = "PUT";
byte[] buffer = new byte[1024];
using (Stream stream = request.GetRequestStream())
{
using (MemoryStream ms = new MemoryStream(docfile))
{
for (int i = ms.Read(buffer, 0, buffer.Length); i > 0; i = ms.Read(buffer, 0, buffer.Length))
stream.Write(buffer, 0, i);
}
}
WebResponse response = request.GetResponse();
response.Close();
}