往Domin 里上传文件代码


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

posted @ 2011-02-15 17:59  spring yang  阅读(408)  评论(0编辑  收藏  举报