469,963 Members | 2,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Is it possible to add a PostedFile to Session

Don't know if this is in the right group, but here goes:

I am working with a website that I am selecting files to be uploaded on one page (ex. UploadAttachment.aspx) and I need to retrieve those file on another page (ex. SubmitPage.aspx) and send them to an Imaging application called ImageRight. I was hoping that I could grab the PostedFiles from the UploadAttachment page, add them to an ArrayList, then send that ArrayList into Session, where I could loop thru upon Submit sending each of the files to the Imaging App. Unfortunately, it doesn't look like PostedFile is Serializable, as I am using a StateServer for my Session State. Any ideas as to how I can resolve my issue?

Space may become an issue, so I don't know if PostedFile.SaveAs (saving it to the server) would be a suitable solution. If there are any other ways to accomplish this, I would be most grateful.

Thanks,

Jason
Jan 9 '06 #1
1 2717
Below some code that shows how to load the file into a byte buffer.
From there you can put it anywhere. Session is maybe not a good idea,

as this might get very big. I store the file into a blog in the db.
Works good.

protected HtmlInputFile fileTextFileUpload;
....

if(( fileTextFileUpload.PostedFile != null ) &&
(fileTextFileUpload.Value.Length > 0))
{
int wordCount = 0;

// Get a reference to PostedFile object
HttpPostedFile myFile = fileTextFileUpload.PostedFile;

string contentType = myFile.ContentType;

// Get size of uploaded file
int nFileLen = myFile.ContentLength;

// Allocate a buffer for reading of the file
byte[] fileBuffer = new byte[nFileLen];

// Read uploaded file from the Stream
myFile.InputStream.Read(fileBuffer, 0, nFileLen);

string[] pathParts = myFile.FileName.Split(new
char[]{'\\','/'});
string fileName = pathParts[pathParts.Length - 1];

//save the file in the db and get the id for the row
long taskID = SaveFile(fileName, ref fileBuffer,
contentType, nFileLen, wordCount);

}
else
{
//Response.Write("File was NOT sent<BR>");
}
}

Cheers
Remy Blaettler
http://www/collaboral.com

Jan 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomasa Gregg | last post: by
4 posts views Thread by bwalke | last post: by
2 posts views Thread by vips | last post: by
7 posts views Thread by Buddy Ackerman | last post: by
reply views Thread by Jgold7 | last post: by
1 post views Thread by daokfella | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.