/// <summary> /// Allows you to add a document to the current document /// library folder from a byte array. /// /// If the document library is versioned, uploading a file /// with the same name creates a new version. /// </summary> /// <param name="file">the file to upload</param> /// <param name="remoteFileName">the filename to use on sharepoint</param> /// <param name="contentType">the mime type (e.g. "application/octet-stream")</param> public SharePointDocument AddDocument(byte[] file, string remoteFileName, string contentType) { // Create the web request object HttpWebRequest request = (HttpWebRequest)WebRequest.Create(siteUrl + "/" + libPath + "/" + remoteFileName); request.Credentials = Credentials; request.ContentType = contentType; request.ContentLength = file.Length; request.Method = "PUT"; // Write the local file to the remote system Stream reqStream = request.GetRequestStream(); reqStream.Write(file, 0, file.Length); reqStream.Close(); // Get a response back from the website HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); SharePointDocument spDoc = new SharePointDocument(siteUrl, libPath, remoteFileName); spDoc.Credentials = Credentials; // Add the newly uploaded document to our collection documents.Add(spDoc); return(spDoc); }
/// <summary> /// Allows you to add a document to the current document /// library folder from a byte array. /// /// If the document library is versioned, uploading a file /// with the same name creates a new version. /// </summary> /// <param name="file">the file to upload</param> /// <param name="remoteFileName">the filename to use on sharepoint</param> /// <param name="contentType">the mime type (e.g. "application/octet-stream")</param> public SharePointDocument AddDocument(byte[] file, string remoteFileName, string contentType) { // Create the web request object HttpWebRequest request = (HttpWebRequest)WebRequest.Create(siteUrl + "/" + folderUrl + "/" + remoteFileName); request.Credentials = Credentials; request.ContentType = contentType; request.ContentLength = file.Length; request.Method = "PUT"; // Write the local file to the remote system Stream reqStream = request.GetRequestStream(); reqStream.Write(file, 0, file.Length); reqStream.Close(); // Get a web response back HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); SharePointDocument spDoc = new SharePointDocument(siteUrl, folderUrl, remoteFileName); spDoc.Credentials = Credentials; return(spDoc); }
/// <summary> /// Allows you to add a document to the current document /// library folder from a byte array. /// /// If the document library is versioned, uploading a file /// with the same name creates a new version. /// </summary> /// <param name="file">the file to upload</param> /// <param name="remoteFileName">the filename to use on sharepoint</param> /// <param name="contentType">the mime type (e.g. "application/octet-stream")</param> public SharePointDocument AddDocument(byte[] file, string remoteFileName, string contentType) { // Create the web request object HttpWebRequest request = (HttpWebRequest) WebRequest.Create(siteUrl + "/" + folderUrl + "/" + remoteFileName); request.Credentials = Credentials; request.ContentType = contentType; request.ContentLength = file.Length; request.Method = "PUT"; // Write the local file to the remote system Stream reqStream = request.GetRequestStream(); reqStream.Write(file, 0, file.Length); reqStream.Close(); // Get a web response back HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); SharePointDocument spDoc = new SharePointDocument(siteUrl, folderUrl, remoteFileName); spDoc.Credentials = Credentials; return spDoc; }
/// <summary> /// Allows you to add a document to the current document /// library folder from a byte array. /// /// If the document library is versioned, uploading a file /// with the same name creates a new version. /// </summary> /// <param name="file">the file to upload</param> /// <param name="remoteFileName">the filename to use on sharepoint</param> /// <param name="contentType">the mime type (e.g. "application/octet-stream")</param> public SharePointDocument AddDocument(byte[] file, string remoteFileName, string contentType) { // Create the web request object HttpWebRequest request = (HttpWebRequest) WebRequest.Create(siteUrl + "/" + libPath + "/" + remoteFileName); request.Credentials = Credentials; request.ContentType = contentType; request.ContentLength = file.Length; request.Method = "PUT"; // Write the local file to the remote system Stream reqStream = request.GetRequestStream(); reqStream.Write(file, 0, file.Length); reqStream.Close(); // Get a response back from the website HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); SharePointDocument spDoc = new SharePointDocument(siteUrl, libPath, remoteFileName); spDoc.Credentials = Credentials; // Add the newly uploaded document to our collection documents.Add(spDoc); return spDoc; }