none
Any sample of using the WebDav api RRS feed

All replies

  • I've added a webclient method to the sample code within the PhotoSample.  But I'm having a heck of time debugging this.  I believe the webDAV site is available because it is  mapped to dev machine and functioning using the same credentials as below.

    The Photo Sample is running on the emulator and appears to save a tempJPG.jpg  in the application storage at "file://applications//Data//D94AD278-3731-4FBF-9F3D-288EA48F9EE5//Data//IsolatedStore//TempJPEG.jpg"  


    I'm attempting to retrieve that file and send it along to the webDAV service. 

    Any suggestions are appreciated.  

      

    void btnAccept_Click(object sender, EventArgs e)
            {
                //Make progress bar visible for the event handler as there may be posible latency.                
      progressBar2.Visibility = Visibility.Visible;
                //Create filename for JPEG in isolated storage
         String tempJPEG = "TempJPEG.jpg";

                //Create virtual store and file stream. Check for duplicate tempJPEG files.
                var myStore = IsolatedStorageFile.GetUserStoreForApplication();
                if (myStore.FileExists(tempJPEG))
                {
                    myStore.DeleteFile(tempJPEG);
                }
                IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);

     

                //Encode the WriteableBitmap into JPEG stream and place into isolated storage.
                Extensions.SaveJpeg(App.CroppedImage, myFileStream, App.CroppedImage.PixelWidth, App.CroppedImage.PixelHeight, 0, 85);
                myFileStream.Close();

                //Create a new file stream.
                myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);

                //Add the JPEG file to the photos library on the device.
                MediaLibrary library = new MediaLibrary();
                Picture pic = library.SavePicture("SavedPicture.jpg", myFileStream);
                myFileStream.Close();

                //Create a new file stream to upload file to webDAV service

                Stream fileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
                string userName = "PHOTOSERVER\\photomanager";
                string password = "snappypassword";

                WebClient wc = new WebClient();
                NetworkCredential credential = new NetworkCredential(userName, password);
                //set the credentials
                wc.Credentials = credential;

                wc.OpenWriteCompleted += (s2, e2) =>
                {
                    System.Threading.Thread thr = new System.Threading.Thread(delegate()
                    {
                        PushData(fileStream, e2.Result);
                        e2.Result.Close();
                        fileStream.Close();
                    });
                    thr.Start();
                };
                wc.OpenWriteAsync(new Uri("http://photos.website.com/"));

                progressBar2.Visibility = Visibility.Collapsed;

            
                textStatus.Text = "Picture saved to the local photos library and your website Album.";

            }

            private static void PushData(Stream input, Stream output)
            {
                byte[] buffer = new byte[4096];
                int bytesRead = 0;
                int tempTotal = 0;

     

                while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
                {
                    output.Write(buffer, 0, bytesRead);
                    tempTotal += bytesRead;
                    _uploadProg++;
                    int percentDone = (int)(((decimal)tempTotal / (decimal)input.Length) * 100);
                    _uploadProg = percentDone;

                    //     ProgressBarUpdated a bit later

                    System.Threading.Thread.Sleep(50);
                }

            }

    Monday, November 8, 2010 11:53 PM
  • Hi, I don't know if there are any samples, but I do have one thought about your code...

    WebDAV is an extension to the HTTP protocol, which adds a bunch of extra verbs to the protocol. I note that WebClient only uses STOR for ftp, and POST for http, so it might not be talking the right language to your WebDAV server. That said, WebDAV does not introduce a new verb for uploading, but perhaps your server is expecting a PUT rather than a POST for its uploads?
    Tuesday, November 9, 2010 12:06 AM
  • Thanks for the reply.    The webDAV is within IIS 7.5.  I've viewed the logs for the website.. the sc-status is 401.  Which suggests authentication.   So even thou the POST has been added to the Request Restrictions as a verb to handle.  The POST is going to be ignored?


    I've since changed thewebclient to  PUT and this is the log entry from the webclient's put    The 401 status is still there and where does this 'file:///..."   originate?
    The file which I believe needed is "file://applications//Data//D94AD278-3731-4FBF-9F3D-288EA48F9EE5//Data//IsolatedStore//TempJPEG.jpg"  


    2010-11-10 01:48:00 W3SVC12 ONIM 10.10.102.98 PUT / - 80 - - HTTP/1.1 NativeHost - file:///Applications/Install/D94AD278-3731-4FBF-9F3D-288EA48F9EE5/Install/ our.snappydomain.com 401 0 5 1509 2717 4717
    Tuesday, November 9, 2010 11:42 PM