473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 2935
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomasa Gregg | last post by:
I need to convert an HTTPPostedFile I am getting from the client to an XMLDocument. The class I am using must have a document. The following gives me an error when I try and build. I cannot...
2
by: CVerma | last post by:
I'm using an html input control (System.web.UI.HTMLControls.HTMLInputFile) to upload files such as msword, excel, jpg, and pdf. I have the encType property set in the form:...
0
by: jason | last post by:
some confusion here. The below code allows me to save a local file to my web server and somehow because the field type is file a local file browse button is rendered. I'm trying to figure out...
4
by: bwalke | last post by:
Help Needed Please!!! With a VB.NET web application, I am trying to save pictures and files to a directory on the web server. However, the web server is not grabbing the Posted Files. For...
2
by: vips | last post by:
I am using asp.net (VB) for uploading the files on my server I am using input type file (runat=server) my code is If ( FileProductImage.PostedFile.ContentLength > 0 ) Then strurl =...
7
by: Buddy Ackerman | last post by:
I created this class Public Class HTMLFileInput : Inherits System.Web.UI.HtmlControls.HtmlInputFile Public Property Data As String Get Return ViewState("HTMLFileInput.Data") End Get Set...
0
by: Jgold7 | last post by:
Not sure which group this should go to, 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...
4
by: ronc85 | last post by:
I'm using ASP.NET 2.0 and C#. With the FileUpload control is it possible to set Wildcards (e.g., *.xls and *.doc) so that when the user clicks the Browse button it defaults to Excel and/or Word...
1
by: daokfella | last post by:
I have a web usercontrol on which is a Webcontrols.FileUpload control. I expose the PostedFile property as a readonly property of the usercontrol. That way, a page has access to it. However,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.