File Upload Dialog

Page 2 of 4 FirstFirst 1234 LastLast
  1. #11

    RE: File Upload Dialog

    Where do we specify the path for the file to be uploaded to.

    Thanks
  2. #12

    RE: File Upload Dialog



    You have 2 options. It'll post back to the same page if you don't specify PostURL (think of it as setting a form's action attribute). If you use the provided HTTPModule (see the web.config), you can specify ProcessorType and provide a class that implements the IFileUploadProcessor interface or extends AbstractFileUploadProcessor. See the Default.aspx.cs file for more details.

    Using the HTTPModule is preferred because it allows you to intercept the request and not buffer the file in memory before storing it. Just add the following to the system.web/httpModules/ node:

    <add name="FileUploadModule" type="ServerControls.FileUploadModule, ServerControls"/>
  3. #13

    RE: File Upload Dialog


    Hi davidhoyt,

    I saw the code, great work!
    The code works fine, but I have in my code that every Session variable is null.

    context.Session is always null, I really don't understand why?

    While context.Request.QueryString["myVariable"] works fine.

    Have you got an idea?

    
    private class FileProcessor : AbstractFileUploadProcessor
            {
                protected override void processUpload(
                                                        HttpContext context,
                                                        IPost post,
                                                        System.IO.Stream stream,
                                                        byte[] buffer,
                                                        int bufferSize,
                                                        System.Text.Encoding encoding)
                {
                    //Saves files to the current project's directory. You should probably do something more intelligent here.
    
                    int read = 0;
                    byte[] _documentbyte = new byte[bufferSize];
                    using (FileStream fs = new FileStream(context.Server.MapPath("~/" + post.FileName), FileMode.Create))
                    {
                        while ((read = stream.Read(buffer, 0, bufferSize)) >= 0)
                            fs.Write(buffer, 0, read);
                        fs.Close();
                    }
    
                    // all fine up to here
    
                    if (context.Session["mySessionName"] == null) return;
                   
                    context.Session["mySessionName"] throws a NullReferenceException !
    
                }
            }
    Thanx a lot

    Matteo
  4. #14

    RE: File Upload Dialog



    Yeah, I think I know exactly why. That class is instantiated and run in an HttpModule before the session information is loaded on a postback. I didn't think about sessions because our app requires sessionless connections.


    I do have a couple of fixes I've been meaning to upload -- but until the session issue has been fixed, you can always use .AdditionalPostParameters() and pass in whatever you might need.


    We use it to pass in the user's ID so we know who to associate the file with.


    The reason I wrote the HTTP module was to get at the file being uploaded before it was cached in memory. I'll look into it.


    I could still really use some help with the design-time portion of it.
  5. #15

    RE: File Upload Dialog

    Hi davidhoyt,

    thanx a lot for reply, ok I see.

    Anyway I solved my problem and adopted the control in my web app and works fine.

    Thanx

    Matteo
  6. #16

    RE: File Upload Dialog

    Hi David. Great job with this control. I had upload your solution on Godaddy shared hosting plan and had give folder permission (read/write) and setup virtual directory but I cannot do it works. The error tells me Upload Error. Can you have an idea of what is going on here? As I said I had upload the solution the only thing had change is:

    using (FileStream fs = new FileStream(context.Server.MapPath("~/Upload/") + post.FileName, FileMode.Create)) {
    Only a folder call Upload. The local version runs great and it's not a permission problem, I had test with the traditional asp.net FileUpload control and works well.

    Any idea?

    Thanks a lot !!!


  7. #17

    RE: File Upload Dialog



    It could be a trust issue - it does use reflection. I don't have much experience in the shared hosting arena and running websites in partial trust environments. I usually have full control of the site and therefore never any permissions problems.

    I'm hoping there's someone out there who could lend a hand with this problem?

    I suppose debugging on the server would be difficult - but you could add a bunch of debug statements and output to a file to see if your handler is being called. You could ad-hoc your way into finding out where the code is dying. Once you find that, I might be able to be of more assistance.

    In summary, insert debug statements throughout the code until you're able to pinpoint where it's dying. Then let me know the class, method name, and line where it's failing along with any pertinent information.
  8. #18

    RE: File Upload Dialog

    Hi euclidez,

    You should be able to determine if the problem is trust related by adding the following <trust> node to your web.config file and testing locally. Your app *should* fail locally under the same conditions.

    Example

    <system.web>
      <trust level="Medium"/>
    </system.web>
    As a general rule, I almost always develop under "Medium" trust... especially if the app/site will eventually be hosted on a shared server. If for no other reason than to uncover potential permission issues early on in the development.

    Not saying this upload thing is 100% a permission issue, but that would be my first guess as well.

    Geoffrey McGill
    Founder & CEO
  9. #19

    RE: File Upload Dialog

    Hi all,

    I have a problem with AdditionalParameters.
    After I save my business object in AjaxEvent, how can I pass the new object ID to the FileUploadDialog parameters?

    Steps:

    - save business object
    - retrieve new object id
    - open file dialog and upload file + new object ID

    Can you provide a simplified way of passing additional params?

    Thanx a lot

    Matteo
  10. #20

    RE: File Upload Dialog

    Just a suggestion,


    Depending on what you are trying to accomplish, you may want to change your logic order to

    - open file dialog and upload file (process will store to path, or database depending on your requirements)

    - save business object with uploaded file path or database id (depends on whether you are saving the file to disc or DB)
    - retrieve new object id (if needed for some other process)

    You probably don't want to create a new business object until you have
    the file uploaded server-side. What if someone starts an upload and
    cancels or they lose connection? The server side will be left with a business object that
    doesn't contain the intended file.


    -MindCore
Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. [CLOSED] multiple file upload and file size at client side
    By mirwais in forum 1.x Premium Help
    Replies: 24
    Last Post: Dec 15, 2014, 5:44 AM
  2. Replies: 1
    Last Post: Jun 23, 2011, 9:37 AM
  3. [CLOSED] File Dialog on Image Click
    By jwf in forum 1.x Premium Help
    Replies: 3
    Last Post: May 21, 2011, 10:03 AM
  4. [CLOSED] file upload - file name is empty
    By stoque in forum 1.x Premium Help
    Replies: 2
    Last Post: May 11, 2011, 8:06 PM
  5. Replies: 5
    Last Post: Oct 16, 2008, 8:18 PM

Posting Permissions