public void Add(DocumentPropertyCollection properties) { if (null != properties) { foreach (DocumentProperty prop in properties) { Add((DocumentProperty)prop.Clone()); } } }
/// <summary> /// Puts a file stream as a document at the specified URI. /// </summary> /// <param name="destinationUri">The full path to the destination document (http://server/site/Folder/Docname.doc)</param> /// <param name="file">Stream to write</param> public void PutDocument(string destinationUri, System.IO.Stream file, DocumentPropertyCollection properties) { WebUrl webUrl = UrlToWebUrl(destinationUri); System.Collections.Specialized.NameValueCollection methodData = new System.Collections.Specialized.NameValueCollection(); // Add general request to stream methodData.Add("method", "put document:" + GetServerExtensionsVersion(webUrl.SiteUrl)); methodData.Add("service_name", ""); methodData.Add("put_option", "overwrite,createdir,migrationsemantics"); methodData.Add("keep_checked_out", "false"); HttpWebRequest req = StartWebRequest(GetAuthorURL(webUrl.SiteUrl), methodData); System.IO.Stream reqStream = req.GetRequestStream(); WriteDocumentData(reqStream, webUrl.FileUrl, file, properties); reqStream.Flush(); reqStream.Close(); HttpWebResponse response = (HttpWebResponse)req.GetResponse(); try { if (!PutDocumentResponseSuccess(GetResponseString(response))) { throw new FrontPageRPCException("Failed to save document.", destinationUri); } } finally { if (null != response) { response.Close(); } } }
/// <summary> /// Writes metadata and file into the stream appropriately for transmission. /// </summary> /// <param name="tw"></param> /// <param name="fileName">Name of the destination file, including folder paths.</param> /// <param name="file"></param> protected void WriteDocumentData(System.IO.Stream stream, string destinationFileName, System.IO.Stream file, DocumentPropertyCollection properties) { System.IO.TextWriter tw = new StreamWriter(stream); DocumentInfo docInfo = new DocumentInfo(); docInfo.ModifiedBy = System.Security.Principal.WindowsIdentity.GetCurrent().Name; docInfo.ModifiedDate = DateTime.Now.ToUniversalTime(); docInfo.DestinationFileName = destinationFileName; docInfo.Title = ExtractFileName(destinationFileName); docInfo.Properties.Add(properties); docInfo.WriteDocumentData(tw); tw.Flush(); // Write raw document data byte[] buffer = new byte[WRITE_BUFFER_SIZE]; int bytesRead = file.Read(buffer, 0, buffer.Length); while (0 != bytesRead) { stream.Write(buffer, 0, bytesRead); bytesRead = file.Read(buffer, 0, buffer.Length); } stream.Flush(); }