A couple weeks ago I wrote message in this newsgroup with subject
"Programmatically upload/edit/delete documents".
At the end of the thread Richard Foltyn wrote:
(c) ----------
Maybe you could upload documents with WEBDAV,
unfortunately i haven't found any information on that
either. Does anyone know how this works?
(/c) ---------
Richard, unfortunatelly, I only yesterday have seen your post :-(
Yes!!! You were absolutely right about World Wide Web Distributed Authoring
and Versioning (WebDAV) protocol.
It's solution of the problem !!!
Using WebDAV you can from a client application programmatically(!!!) :
- access folders and items;
- create folders;
- create items;
- delete items and folders;
- copy/move folders/items from one place to another;
- searching for items and folders;
- lock/unlock items (for exclusive write);
- and anything you want........
And at last some simple examples in VB.NET (these examples could be written
also in the any other languages - C#, C++, VBScript or JScript)
Private Sub Test()
Dim answer As String = ""
' Create Folder
answer = CreateFolder("http://<sitename>/<subsitename>/Shared
Documents/MyNewFolder")
' Delete Folder
answer = DeleteItem("http://<sitename>/<subsitename>/Shared
Documents/MyNewFolder")
' Create Item
answer = CreateItem("http://<sitename>/<subsitename>/Shared
Documents/test.txt", "...my content...blah-blah-blah...")
' Delete Item
answer = DeleteItem("http://<sitename>/<subsitename>/Shared
Documents/test.txt")
End Sub
Private Function CreateFolder(ByVal strFolderURI As String) As String
Dim Request As System.Net.HttpWebRequest
Dim Response As System.Net.HttpWebResponse
Try
' Create the HttpWebRequest object.
Request = CType(System.Net.WebRequest.Create(strFolderURI),
System.Net.HttpWebRequest)
' Add the network credentials to the request.
Request.Credentials = CredentialCache.DefaultCredentials
' Specify the method.
Request.Method = "MKCOL"
' Send the MKCOL method request and get the response from the server.
Response = Request.GetResponse()
' Clean up.
Response.Close()
Return "Folder created at " + strFolderURI + "."
Catch ex As Exception
Return ex.Message
End Try
End Function
Private Function CreateItem(ByVal strFolderURI As String, ByVal content As
String) As String
Dim Request As System.Net.HttpWebRequest
Dim Response As System.Net.HttpWebResponse
Try
' Create the HttpWebRequest object.
Request = CType(System.Net.WebRequest.Create(strFolderURI),
System.Net.HttpWebRequest)
' Add the network credentials to the request.
Request.Credentials = CredentialCache.DefaultCredentials
' Specify the method.
Request.Method = "PUT"
Request.ContentType = "text/plain"
Request.ContentLength = content.Length
Request.Headers.Add("Translate", "f")
Dim myWriter As StreamWriter
Try
myWriter = New StreamWriter(Request.GetRequestStream())
myWriter.Write(content)
Catch e As Exception
Return e.Message
Finally
myWriter.Close()
End Try
' Send the MKCOL method request and get the response from the server.
Response = Request.GetResponse()
' Clean up.
Response.Close()
Return "Item created at " + strFolderURI + "."
Catch ex As Exception
Return ex.Message
End Try
End Function
Private Function DeleteItem(ByVal strSourceURI As String) As String
Dim Request As System.Net.HttpWebRequest
Dim Response As System.Net.HttpWebResponse
Try
' Create the HttpWebRequest object.
Request = CType(System.Net.WebRequest.Create(strSourceURI),
System.Net.HttpWebRequest)
' Add the network credentials to the request.
Request.Credentials = CredentialCache.DefaultCredentials
' Specify the method.
Request.Method = "DELETE"
' Send the DELETE method request and get the
' response from the server.
Response = Request.GetResponse()
' Clean up.
Response.Close()
Return "Item successfully deleted."
Catch ex As Exception
' Catch any exceptions. Any error codes from the
' DELETE method requests on the server will be caught
' here, also.
Return ex.Message
End Try
End Function
If somebody will have any questions about WebDAV feel free to contact me :-)
Thanks for attention,
Ruslans
I have a question about deleting a calendar appointment. I can
successfully delete an appointment with the following code, but how
would I send out the associated cancellation notices that we're used
to with MSOutlook. When a meeting is cancelled or updated, a notice
is sent to all attendees. I would like to be able to do that when
deleting or modifying meetings with the code below. Thanks for your
help!!!!
public static void DeleteMeeting(string MeetingURL, string SalesID,
string Password, string Domain)
{
try
{
System.Net.HttpWebRequest Request;
System.Net.WebResponse Response;
System.Net.CredentialCache MyCredentialCache;
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add(new System.Uri(MeetingURL),"NTLM",
new System.Net.NetworkCredential(SalesID, Password, Domain));
// Create the HttpWebRequest object.
Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(MeetingURL);
// Add the network credentials to the request.
Request.Credentials = MyCredentialCache;
// Specify the DELETE method.
Request.Method = "DELETE";
// Send the DELETE method request.
Response = (System.Net.HttpWebResponse)Request.GetResponse();
// Close the HttpWebResponse object.
Response.Close();
}
catch(Exception ex)
{
// Catch any exceptions. Any error codes from the DELETE
// method request on the server will be caught here, also.
string excpt = ex.Message.ToString();
DBI.Framework.Exception temp = new DBI.Framework.Exception("Error
in DeleteMeeting method of MeetingManager class." + ex.Message,ex);
}
}