Upload Images to Folder

Last post 07-24-2012, 8:01 AM by Kenneth. 4 replies.
Sort Posts: Previous Next
  •  07-23-2012, 6:32 AM 74193

    Upload Images to Folder

    Hello:
     
    When I upload an image file, the upload starts and i see the checkmark next to the file name that shows the upload was completed. However when I go to the folder the that the images should be in; nothing is there. Here is my code:
     
     
     <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }
        void ButtonPostBack_Click(object sender, EventArgs e)
        {
            InsertMsg("You clicked a PostBack Button.");
        }

        void Uploader_FileUploaded(object sender, UploaderEventArgs args)
        {
            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");
            args.CopyTo("~/images" + args.FileName);
            System.IO.Stream data = args.OpenStream();
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Simple Upload with Progress (Custom Validation) </title>
        <link rel="stylesheet" href="demo.css" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="content">
                <asp:ScriptManager ID="Scriptmanager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <h2>
                            Simple Upload with Progress (Custom Validation)
                        </h2>
                        <p>
                            A sample demonstrating how to create user-defined validation functions for an upload
                            control. In this example, we defined two validation rules:</p>
                        <ul>
                            <li>Maximum file size: 1000K</li>
                            <li>Allowed file types: jpeg, jpg, gif,png </li>
                        </ul>
                        <p>
                            Click the following button to upload.
                        </p>
                        <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertText="Upload" OnFileUploaded="Uploader_FileUploaded">
                            <ValidateOption AllowedFileExtensions="jpeg,jpg,gif,png" MaxSizeKB="1000" />
                        </CuteWebUI:Uploader>
                        <p>
                            Server Trace:
                            <br />
                            <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                        </p>
                        <asp:Button ID="ButtonPostBack" Text="This is a PostBack button" runat="server" OnClick="ButtonPostBack_Click" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </form>
    </body>

  •  07-23-2012, 9:00 AM 74197 in reply to 74193

    Re: Upload Images to Folder

    Hi LVWiseguy,
     
    Should be    args.CopyTo("~/images/"+args.FileName); 
     
    Not args.CopyTo("~/images" + args.FileName); 
     
    Regards,
     
    Ken 
  •  07-23-2012, 10:13 AM 74205 in reply to 74197

    Re: Upload Images to Folder

    It is still not showing up in the folder

    --
    <script runat="server">
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }
        void ButtonPostBack_Click(object sender, EventArgs e)
        {
            InsertMsg("You clicked a PostBack Button.");
        }
        void Uploader_FileUploaded(object sender, UploaderEventArgs args)
        {
            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");
            args.CopyTo("~/images/"+args.FileName);
            System.IO.Stream data = args.OpenStream();
        }
    </script>
     
  •  07-23-2012, 1:20 PM 74206 in reply to 74205

    Re: Upload Images to Folder

    Is there a script that I can insert to catch any errors? My folder permission are fine. I tested it with the basic ASP.Net Upload and it works fine. I like the CuteSoft version because of the progress bar. 
  •  07-24-2012, 8:01 AM 74218 in reply to 74206

    Re: Upload Images to Folder

    hi LVWiseguy,
     
    Please try the example page below directly, does it work on your end?
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head id="Head1" runat="server">  
    7. </head>  
    8.   
    9. <script runat="server">  
    10.     protected void uploader1_FileUploaded(object sender, UploaderEventArgs args)  
    11.     {  
    12.         args.CopyTo("~/images/" + args.FileName);   
    13.     }  
    14. </script>  
    15.   
    16. <body>  
    17.     <form id="Form1" runat="server">  
    18.         <CuteWebUI:UploadAttachments ID="uploader1" runat="server" OnFileUploaded="uploader1_FileUploaded">  
    19.         </CuteWebUI:UploadAttachments>  
    20.     </form>  
    21. </body>  
    22. </html>  
    How to catch the upload error please refer to http://www.ajaxuploader.com/document/scr/How-to-catch-uploader-error.htm
     
    Regards,
     
    Ken 
View as RSS news feed in XML