Is it possible to add a PostedFile to Session

J

Jgold7

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
 
R

Remy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top