views:

217

answers:

2

Hello everyone,

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.

A: 

Would this answer to a similar question help?

JumpingJezza
This doesn't answer my question. I need to copy a file to a local folder in my project.
Ephismen
A local folder in your project = the web server doesn't it?
JumpingJezza
+1  A: 

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

Enough already
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?
Ephismen
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).
Enough already
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.
Ephismen
@Ephismen: Answer updated to include specific example.
Enough already
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!
Ephismen
Please add your own answer, or select an answer, to close off the question. Cheers.
Enough already