0

In my silverlight application I would like to be able to select a file from an OpenFileDialog window and upload/copy it to a local folder in my Silverlight project. I am already able to setup a OpenFileDialog window and set some options to it, but unfortunately I can't find a way to create a filestream and then copy it to a local folder.

private void Change_Avatar_Button_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openfile = new OpenFileDialog();
        openfile.Multiselect = false;
        openfile.Filter = "Images files (*.bmp, *.png)|*.bmp;*.png";

        if ((bool)openfile.ShowDialog())
        {

        }
    }

I've tried looking at many tutorials on the net, but they only seem to send the file directly to the UploadFile method in silverlight what I do not want to do at the moment.

Thank you, Ephismen.

1 Answer 1

1

You can't just write files to local folders without prompting the user a second time (e.g. save as dialog http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx)

You could write it to isolated storage instead: http://blogs.silverlight.net/blogs/msnow/archive/2009/05/21/71909.aspx.

If you want specific examples (e.g. going straight from OpenFileDialog to Isolated storage) I strongly recommend you use Google. The first match on "silverlight openfiledialog to isolated storage" is this: http://forums.silverlight.net/forums/t/201362.aspx

5
  • What I'm trying to do exactly is to select a file, copy it to a directory, and upload it to a web service so other users can see it. If one day I launch my silverlight application again and load information from the web service, I would like to check this 'local folder' if the file already exist and if it does there are no need to download it again. I don't know if i made myself clear?
    – Aymeric
    Sep 16, 2010 at 8:43
  • In that case your best option is to use isolated storage. Think of it as a super cookie (Silverlight is a web browser object after all). Sep 16, 2010 at 9:06
  • The link you gave me use the IsoltedStorage but not for OpenFileDialog. I am totaly lost with getting file path, putting it into some sort of Stream and writing it into the isolatedStorage. So if anyone can provie me with some example or help it would be greatly appreciated. Thank you.
    – Aymeric
    Sep 16, 2010 at 13:43
  • Thank you for you answer. I had actually succeeded doing that a few days ago but I made it even more simple with the information you provided. Thank you!
    – Aymeric
    Sep 20, 2010 at 12:35
  • Please add your own answer, or select an answer, to close off the question. Cheers. Sep 20, 2010 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.