Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Upload an image file and save it to SQL Server (Without using aspx file)
6 replies. Latest Post by cris168 on January 13, 2009.
(0)
cris168
Member
10 points
32 Posts
01-12-2009 7:59 PM |
Hello Gurus,
I hope you can help me on. How to upload an image by using a dialog box and then, save it to SQL Server Database. I tried to search and never find any solution.
Sincerely,
Cris
bryant
Star
9937 points
1,629 Posts
01-12-2009 8:59 PM |
You have to have some logic on the server side (be it aspx or ashx). Something has to accept the upload and write it to the database. The uploader I like best is Silverlight File Upload. You could easily customize the FileUpdate.ashx.cs to write the file to the database instead of a file.
01-12-2009 10:21 PM |
Hello Bryant,
FileStream
using
OpenFileDialog
file.Multiselect =
{
fs.Close();
}
Thanks,Cris
01-12-2009 10:36 PM |
Follow up.. Please try this code in the code behind of .xaml file. Not in the Windows Form.
jackbond
Contributor
2820 points
725 Posts
01-12-2009 10:37 PM |
cris168:FileStream fs = new FileStream(file.File.Name, FileMode.OpenOrCreate, FileAccess.Read); // this line of code will create an ERROR...
You're close, but you don't create a new FileStream, this is the correct pattern...
ofd.ShowDialog();
MarkBetz
Participant
1142 points
211 Posts
01-12-2009 10:48 PM |
According to the MSDN documentation for the FileStream ctor:
This member has a SecurityCriticalAttribute attribute, which restricts it to internal use by the .NET Framework for Silverlight class library. Application code that uses this member throws a MethodAccessException.
So, I think what you have to do is call FileInfo.OpenRead() to get a stream back. You get the FileInfo from the OpenFileDialog's properties.
Edit: Jack beat me to it. :)
01-13-2009 9:32 AM |
For the three Gurus who help me.
Thanks a lot it works now.