1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
| string hosturl = "http://sharepoint"; string weburl = "/websites"; string fileurl = "Dokumente/test.pdf"; bool overwrite = true; string title = "test";
string serviceName = hosturl + weburl + "/_vti_bin/_vti_aut/author.dll";
string method = "put document: 12.0.0.000"; string document = fileurl; string metaInfo = string.Empty; string putOption = overWrite ? "overwrite" : "edit"; string keepCheckedOutOption = "false"; string comment = string.Empty; string returnStr = string.Empty; byte[] data; string returnError = string.Empty;
string fpRPCCallStr = "method={0}&service_name={1}&document=[document_name={2};meta_info=[{3}]]&put_option={4}&comment={5}&keep_checked_out={6}";
method = HttpUtility.UrlEncode(method); putOption = HttpUtility.UrlEncode(putOption); metaInfo = "vti_title;SW|" + title; fpRPCCallStr = String.Format(fpRPCCallStr, method, serviceName, document, metaInfo, putOption, comment, keepCheckedOutOption);
byte[] fpRPCCall = System.Text.Encoding.UTF8.GetBytes(fpRPCCallStr + "\n");
WebRequest wReq = WebRequest.Create(serviceName); wReq.Credentials = nwc; wReq.Method = "POST"; wReq.Proxy = GetDefaultProxy(nwc); wReq.ContentType = "application/x-vermeer-urlencoded"; wReq.Headers.Add("X-Vermeer-Content-Type", "application/x-vermeer-urlencoded"); wReq.Timeout = Timeout.Infinite; wReq.ContentLength = fpRPCCall.Length + fileBinary.Length;
Stream requestStream = wReq.GetRequestStream();
requestStream.WriteTimeout = System.Threading.Timeout.Infinite; requestStream.Write(fpRPCCall, 0, fpRPCCall.Length);
requestStream.Flush();
int bytesRead = 0; int chunkSize = 4096; int tailSize; int chunkNum = Math.DivRem((int)fileBinary.Length, chunkSize, out tailSize);
int sleep = 10;
for (int j = 0; j < chunkNum; j++) { data = new byte[chunkSize]; bytesRead = fileBinary.Read(data, 0, chunkSize);
requestStream.Write(data, 0, chunkSize); requestStream.Flush(); if(((j+1)*chunkSize%(1024*1024))==0) Console.WriteLine((j + 1) * chunkSize / 1024 + "kB"); Thread.Sleep(sleep); }
if (tailSize > 0) { data = new byte[tailSize]; bytesRead = fileBinary.Read(data, 0, tailSize); requestStream.Write(data, 0, tailSize); requestStream.Flush(); }
requestStream.Flush(); requestStream.Close(); requestStream.Dispose();
WebResponse response = wReq.GetResponse(); |