none
AjaxFileUpload1怎么上传文件 RRS feed

  • 问题

  • 在  ajaxcontroltoolkit 里面有一个   AjaxFileUpload   控件 , 他的后台代码是怎么写的??

    我的代码是这样的

    <body  >
        <form id="form1" runat="server">
        <div>
            <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
            </ajaxToolkit:ToolkitScriptManager>
            <ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" 
                onuploadcomplete="AjaxFileUpload1_UploadComplete" 
                onuploadcompleteall="AjaxFileUpload1_UploadCompleteAll" />
    
    
        </div>
        </form>
    </body>

    后台

    protected void AjaxFileUpload1_UploadComplete(object sender,
                AjaxControlToolkit.AjaxFileUploadEventArgs e)
            {
                string a = "asd";
              
            }

    为什么这样写都会报错:

    未能找到路径“C:\Users\Administrator\AppData\Local\Temp\_AjaxFileUpload\D2D6903F-20D5-70D9-7BCF-185EC7D2D3DF\”的一部分。

    这个控件是怎么上传文件的??求助,求代码

    2013年10月26日 7:25

答案

  • 你好,楼主:

    在拖拽了这个控件之后还请务必在web.config做配置:

    <system.web>
      <httpHandlers>
        <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
      </httpHandlers>
    </system.web>
    <system.webServer>
      <handlers>
        <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
      </handlers>
    </system.webServer>

    我建议你可以直接调用该控件的SaveAs方法,保存到服务器的相对路径文件夹中(写在UploadComplete事件中):

    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
            {
                AjaxFileUpload1.SaveAs(MapPath("~/" + new FileInfo(e.FileName)));
            }

    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    2013年10月26日 9:45
    版主

全部回复

  • 参考下面文章的实现代码:

    http://www.cnblogs.com/hyl8218/archive/2009/12/21/1629210.html


    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample

    2013年10月26日 8:50
  • 你好,楼主:

    在拖拽了这个控件之后还请务必在web.config做配置:

    <system.web>
      <httpHandlers>
        <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
      </httpHandlers>
    </system.web>
    <system.webServer>
      <handlers>
        <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
      </handlers>
    </system.webServer>

    我建议你可以直接调用该控件的SaveAs方法,保存到服务器的相对路径文件夹中(写在UploadComplete事件中):

    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
            {
                AjaxFileUpload1.SaveAs(MapPath("~/" + new FileInfo(e.FileName)));
            }

    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    2013年10月26日 9:45
    版主
  • 太感谢了
    2013年10月28日 7:26