Is it possible to add a PostedFile to Session

Discussion in 'ASP .Net' started by Jgold7, Jan 9, 2006.

  1. Jgold7

    Jgold7 Guest

    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
     
    Jgold7, Jan 9, 2006
    #1
    1. Advertisements

  2. Jgold7

    Remy Guest

    Below some code that shows how to load the file into a byte buffer.
    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
     
    Remy, Jan 9, 2006
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.