Adding files to uploaded list programmatically

Last post 11-20-2009, 11:09 PM by cutechat. 2 replies.
Sort Posts: Previous Next
  •  11-20-2009, 4:59 AM 57318

    Adding files to uploaded list programmatically

    I'm am using the following lines of code:
     
    System.IO.Stream stream = File.Open(path, System.IO.FileMode.Open);
    cwuploader.Items.Add(
    Convert.ToInt32(stream.Length), filename, stream);
     
    The code is working, but for medium size files (50 MB+), the procedure takes way too much server resources.
    Could a solution be to make a false stream object containing an empty dummy file?
    Why does the uploader need the stream anyway?
  •  11-20-2009, 7:26 AM 57321 in reply to 57318

    Re: Adding files to uploaded list programmatically

    To follow up:
     
    I have made a little hack by sending a stream to the Itemlist containing the id in my database table which refer to the file I want to show in the list. I am using this id when the user clicks the Remove button later, to be able to remove the selected file from database and hard drive.
     
    My next problem is that even when I send the correct file size, the filesize shown on the rendered page shows the filesize of the dummystream.
     
    Stream stream = File.Open(Server.MapPath("file.pdf"), FileMode.Open);
    byte
    [] strfilid = {1, 2};
    Stream dummystream = new MemoryStream(strfilid);
    cwuploader.Items.Add(
    stream.length, "filename.pdf", dummystream);
     
    The above example returns when rendered:
    filename.pdf (2Bytes)
  •  11-20-2009, 11:09 PM 57330 in reply to 57318

    Re: Adding files to uploaded list programmatically

    Hi,
     
    If you just want to add an existing item , I suggest you check the advanced sample , the EditTopic.aspx sample , which allow you add an 'custom' item without copying the data.
     
    (implementing the CuteWebUI.IAttachmentProvider and use AddCustomAttachment method)
     
    Regards,
    Terry
View as RSS news feed in XML