Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
rajesh.varma  
#1 Posted : Sunday, August 2, 2009 9:55:47 PM(UTC)
rajesh.varma

Rank: Newbie

Groups: Member
Joined: 7/27/2009(UTC)
Posts: 1

Hi,
I want the save the uploaded files directly into database in byte format without saving the file anywhere else. I want to convert the uploaded file into System.IO.FileStream in C#. How is it possible to convert the uploaded file into Stream or bytes ?
Fedor  
#2 Posted : Monday, August 10, 2009 5:59:45 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,556

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
Quote:
I want the save the uploaded files directly into database in byte format without saving the file anywhere else. I want to convert the uploaded file into System.IO.FileStream in C#. How is it possible to convert the uploaded file into Stream or bytes ?


I am sorry for delay. In you use Image Uploader without ASP.NET control, then System.Web.HttpPostedFile.InputStream is what you need:

(code is untested)
Code:
HttpPostedFile sourcefile = Request.Files["SourceFile_1"];
Byte[] data = new Byte[sourceFile.ContentLength]
sourceFile.InputStream.Read(data, 0, sourceFile.ContentLength);


If you use Image Uploader ASP.NET control, then you should use the following code:

(code is untested)
Code:
	private void ImageUploader1_FileUploaded(object sender, FileUploadEventArgs e)
{
	Byte[] data = new Byte[e.SourceFile.ContentLength]
	e.SourceFile.InputStream.Read(data, 0, e.SourceFile.ContentLength);
}
Best regards,
Fedor Skvortsov
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.