WebDavFile class supports file operations on a remote WebDAV server.
For a list of all members of this type, see WebDavFile Members.
System.Object
Resco.Net.NetFile
Resco.Net.WebDavFile
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
As the first step you need to create WebDavFile object using static Create method.
The remaining class methods support classic file operations:
All supported methods are asynchronous. To use them you need to supply
asyncState object. This object serves for a single purpose - it is passed back in the callback. (See for example the State property). Supply null if you don't need this object.All methods return a NetRequest instance. You can use this object to abort the operation.
File operations are one-shot operations. Respective callback is called once - upon the operation completion.
Use the Succeeded property to see if the operation completed successfully.
In case of recursive operations the callback is called after each recursion step. For more information see the description of individual methods.
Open remote directory
WebDavFile dir = WebDavFile.Create("https://myServer/xyz/MyBackupDir", "login", "password");
Debug.Assert( dir.IsDirectory ) ;
Enumeration of a remote directory
dir.StartEnum( delegate(NetEnumResult er)
{
NetFile file;
while ((file = er.GetNextFile()) != null)
Debug.WriteLine( "File name: {0}", file.Name ) ;
});
Download file
dir.Download( @"\MyDir\MyFile.x", delegate(NetAsyncResult ar)
{
if( ar.Succeeded )
;// use ar.Stream to save downloaded data
} );
Instead of anonymous delegate you can use explicit callback, for example
private void DefaultAsyncCallback(NetAsyncResult ar)
{
Debug.WriteLine("Request {0}:\n{1}", ar.Succeeded ? "Succeeded" : "Failed", ar.Response);
}
Rename
netFile.Rename( "NewFileName", false, DefaultAsyncCallback);
Delete
netFile.Delete( DefaultAsyncCallback, null);
Upload data
var stream = new MemoryStream( System.Text.Encoding.UTF8.GetBytes("Some text") );
dir.Upload(stream, "Test.txt", DefaultAsyncCallback);
Sample callback used for recursive download/upload
private void DefaultPartialAsyncCallback(NetAsyncResult ar)
{
if (ar is PartialNetAsyncResult)
{
// Called for directory upload/download
var res = (ar as PartialNetAsyncResult);
Debug.WriteLine( "{0} -> {1} : {2}", res.File.FullPath, res.LocalPath, (res.Succeeded ? "OK" : res.Response) );
if (!res.Succeeded)
res.Continue = false; // break the loop (we could also ignore the error and continue)
}
else
{
Debug.WriteLine("Request {0}:\n{1}", ar.Succeeded ? "Succeeded" : "Failed", ar.Response);
}
}
Backup IsolatedStorage (Windows Phone)
dir.Upload( @"\", DefaultPartialAsyncCallback );
Namespace: Resco.Net
Assembly: Resco.Net.CF3 (in Resco.Net.CF3.dll)
WebDavFile Members | Resco.Net Namespace