473,408 Members | 2,477 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,408 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 2937
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.