Domin in the code to upload files


Road address upload file: fileURL

docfile: byte [] type of the byte stream

 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();
        }

Reproduced in: https: //www.cnblogs.com/springyangwc/archive/2011/02/15/1955466.html

Guess you like

Origin blog.csdn.net/weixin_34411563/article/details/93340809