A few questions..

Last post 01-23-2012, 9:24 AM by kbranden. 4 replies.
Sort Posts: Previous Next
  •  01-20-2012, 2:29 PM 72772

    A few questions..

    If you don't specify a TempDirectory in your web config. Does it just load to memory and then when you use CopyTo it just copies it from memory?
     
    Also, in Visual Studio running in debug mode (after setting a tempdirectory AND when not setting a TempDirectory) and you use the MoveTo method, I get a 'The process cannot access the file because it is being used by another process.' error. I can use the CopyTo and it works however. This might be a permissions problem?
  •  01-20-2012, 3:19 PM 72773 in reply to 72772

    Re: A few questions..

    Hi kbranden,
     
    1. If you did not get the TempDirectly, then the uploader will use the default system temp folder C:\Users\ken\AppData\Local\Temp\AjaxUploaderTemp\, not copies from memory.
     
    2. Get the  "The process cannot access the file because it is being used by another process.' error because you try to remove the temp file by MoveTo method. in this time other process still using the temp file. you can try the example below, it use MoveTo too, but will not get any problem.
    <%@ Page Language="C#" %>
    <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        protected void uploader1_FileUploaded(object sender, UploaderEventArgs args)
        {
            args.MoveTo("~/"+args.FileName);
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>example</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:Label ID="l1" runat="server"></asp:Label>
            <CuteWebUI:UploadAttachments ID="uploader1" runat="server" OnFileUploaded="uploader1_FileUploaded">
            </CuteWebUI:UploadAttachments>
        </form>
    </body>
    </html>
     
    Regards,
     
    Ken 
  •  01-20-2012, 3:31 PM 72775 in reply to 72773

    Re: A few questions..

    Actually, I am doing that....
    1. protected void Uploader1_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)  
    2.     {  
    3.         System.Drawing.Image postedImage = System.Drawing.Image.FromStream(args.OpenStream());  
    4.           
    5.   
    6.         Session["ImageHeight"] = postedImage.Height.ToString();  
    7.         Session["ImageWidth"] = postedImage.Width.ToString();  
    8.   
    9.         string OrigFilename = Path.GetFileName(args.FileName);  
    10.         string OrigExtention = OrigFilename.Substring(OrigFilename.Length - 4, 4);  
    11.   
    12.         System.Guid newGUID = System.Guid.NewGuid();  
    13.   
    14.         string UploadedImageDir = Server.MapPath("UploadedImages/");  
    15.   
    16.   
    17.         string GUIDFilename = newGUID.ToString() + OrigExtention;  
    18.         string PathAndFileToUploadedImagesDir = UploadedImageDir + GUIDFilename;  
    19.   
    20.           
    21.         args.MoveTo(PathAndFileToUploadedImagesDir);  
    22. }  
  •  01-23-2012, 8:36 AM 72802 in reply to 72775

    Re: A few questions..

    Ken,
     
    The code above is what I am using and which still gives me the ''The process cannot access the file because it is being used by another process.'' error.  In case I didn't make myself clear.
     
    Thanks,
    Kevin
  •  01-23-2012, 9:24 AM 72805 in reply to 72802

    Re: A few questions..

    Ok, nvm..  The reason it wasn't working was because of the..
    System.Drawing.Image postedImage = System.Drawing.Image.FromStream(args.OpenStream());   
    I have changed the method to that below and everything seems to be working much better. I'm going to test this out with large files (120meg) and if it works.. $$ is on the way.
     
    1. protected void Uploader1_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)  
    2.    {  
    3.        string UploadedImageDir = Server.MapPath("UploadedImages/");  
    4.   
    5.        string OrigFilename = args.FileName;  
    6.        string OrigExtention = OrigFilename.Substring(OrigFilename.Length - 4, 4);  
    7.   
    8.        System.Guid newGUID = System.Guid.NewGuid();  
    9.   
    10.   
    11.        string GUIDFilename = newGUID.ToString() + OrigExtention;  
    12.        string PathAndFileToUploadedImagesDir = UploadedImageDir + GUIDFilename;  
    13.   
    14.        args.MoveTo(UploadedImageDir + GUIDFilename);  
    15.   
    16.        System.Drawing.Image postedImage = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(UploadedImageDir + GUIDFilename);  
    17.   
    18.        Session["ImageHeight"] = postedImage.Height.ToString();  
    19.        Session["ImageWidth"] = postedImage.Width.ToString();  
    20.    }  
     
View as RSS news feed in XML