/// <summary> /// Has WSS parse the site vs. file/folder portion of a URL. /// </summary> /// <param name="uri"></param> /// <returns></returns> public WebUrl UrlToWebUrl(string url) { WebUrl webUrl = new WebUrl(); Uri aUri = new Uri(url); System.Collections.Specialized.NameValueCollection methodData = new System.Collections.Specialized.NameValueCollection(); methodData.Add("method", "url to web url"); methodData.Add("url", aUri.AbsolutePath); methodData.Add("flags", "0"); HttpWebRequest req = StartWebRequest(GetVtiRPC(aUri.AbsoluteUri), methodData); System.IO.Stream reqStream = req.GetRequestStream(); reqStream.Flush(); reqStream.Close(); string response = GetResponseString((HttpWebResponse)req.GetResponse()); string internalError = this.CheckForInternalErrorMessage(response); if (internalError != string.Empty) { throw new FrontPageRPCException(internalError, url); } else { webUrl.SiteUrl = aUri.GetLeftPart(System.UriPartial.Authority) + GetReturnValue(response, "webUrl"); webUrl.FileUrl = System.Web.HttpUtility.UrlDecode(GetReturnValue(response, "fileUrl")); } return(webUrl); }
/// <summary> /// Retrieves document meta-information. /// </summary> /// <param name="documentUrl"></param> /// <returns></returns> public DocumentInfo GetDocumentMetaInfo(string documentUrl) { try { WebUrl webUrl = UrlToWebUrl(documentUrl); System.Collections.Specialized.NameValueCollection methodData = new System.Collections.Specialized.NameValueCollection(); methodData.Add("method", "getDocsMetaInfo:" + GetServerExtensionsVersion(webUrl.SiteUrl)); methodData.Add("service_name", ""); methodData.Add("listHiddenDocs", "true"); methodData.Add("listLinkInfo", "true"); methodData.Add("url_list", "[" + webUrl.FileUrl + "]"); HttpWebRequest req = StartWebRequest(GetAuthorURL(webUrl.SiteUrl), methodData); System.IO.Stream reqStream = req.GetRequestStream(); reqStream.Flush(); reqStream.Close(); HttpWebResponse response = (HttpWebResponse)req.GetResponse(); System.IO.Stream responseStream = response.GetResponseStream(); System.IO.StreamReader sr = new StreamReader(responseStream); string responseData = sr.ReadToEnd(); DocumentInfo docInfo = ParseMetaInformationResponse(responseData); return(docInfo); } catch (Exception e) { throw new FrontPageRPCException("SetDocumentMetaInfo failed", documentUrl, e); } }
/// <summary> /// Checks a document into the Library supplied in the url; /// </summary> /// <param name="documentUrl">The full path to the destination document (http://server/site/Folder/Docname.doc)</param> /// <returns></returns> public bool CheckInDocument(string documentUrl, string comment) { bool rtn = false; WebUrl webUrl = UrlToWebUrl(documentUrl); NameValueCollection methodData = new NameValueCollection(); methodData.Add("method", "checkin document: " + GetServerExtensionsVersion(webUrl.SiteUrl)); methodData.Add("service_name", "/"); methodData.Add("document_name", webUrl.FileUrl); methodData.Add("comment", comment); methodData.Add("keep_checked_out", "false"); HttpWebRequest request = this.StartWebRequest(GetAuthorURL(webUrl.SiteUrl), methodData); System.IO.Stream reqStream = request.GetRequestStream(); reqStream.Flush(); reqStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader read = new StreamReader(stream); string resp = read.ReadToEnd(); if (!CheckInAndOutDocumentResponseSuccess("method=checkin", resp)) { throw new ApplicationException("Failed to check out document."); } string innerException = CheckForInternalErrorMessage(resp); if (innerException != string.Empty) { throw new FrontPageRPCException(innerException, documentUrl); } else { rtn = true; } return(rtn);; }
/// <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> /// Invokes the get document FP RPC call and returns the HttpWebResponse. /// </summary> /// <param name="documentUrl">Complete url to the document, including folders.</param> /// <param name="getOption">Options to apply for retrieving the document: /// <list> /// <item>None</item> /// <item>chkoutExclusive</item> /// <item>chkoutNonExclusive</item> /// </list> /// See the SharePoint Front Page RPC documentation for more details <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/tsfppget_option_SV01031279.asp"></a> /// </param> /// <returns></returns> private HttpWebResponse GetDocumentResponse(string documentUrl, string getOption) { WebUrl webUrl = UrlToWebUrl(documentUrl); System.Collections.Specialized.NameValueCollection methodData = new System.Collections.Specialized.NameValueCollection(); methodData.Add("method", "get document:" + GetServerExtensionsVersion(webUrl.SiteUrl)); methodData.Add("service_name", ""); methodData.Add("document_name", webUrl.FileUrl); methodData.Add("get_option", getOption); methodData.Add("timeout", "10"); HttpWebRequest req = StartWebRequest(GetAuthorURL(webUrl.SiteUrl), methodData); System.IO.Stream reqStream = req.GetRequestStream(); reqStream.Flush(); reqStream.Close(); HttpWebResponse response = (HttpWebResponse)req.GetResponse(); return(response); }
/// <summary> /// Undoes a checkout of a file from a source control database. /// If the file had changes made since it was checked out, this method causes those changes to be lost /// </summary> /// <param name="documentUrl">The full path to the destination document (http://server/site/Folder/Docname.doc)</param> /// <returns></returns> public bool UnCheckOutDocument(string documentUrl) { bool rtn = false; WebUrl webUrl = UrlToWebUrl(documentUrl); NameValueCollection methodData = new NameValueCollection(); methodData.Add("method", "uncheckout document: " + GetServerExtensionsVersion(webUrl.SiteUrl)); methodData.Add("service_name", "/"); methodData.Add("document_name", webUrl.FileUrl); methodData.Add("force", "false"); HttpWebRequest request = this.StartWebRequest(GetAuthorURL(webUrl.SiteUrl), methodData); System.IO.Stream reqStream = request.GetRequestStream(); reqStream.Flush(); reqStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader read = new StreamReader(stream); string resp = read.ReadToEnd(); string innerException = CheckForInternalErrorMessage(resp); if (innerException != string.Empty) { throw new FrontPageRPCException(innerException, documentUrl); } else { rtn = true; } return(rtn); }