开发者

Cannot upload mp3 using C#, please help!

Can someone tell me what's wrong with this code? I'm trying to upload a mp3 with this piece of code and when i try to do so i get a "Internet Explorer cannot display the webpage"

<asp:FileUpload ID="FileUpload1" runat="server" />

<asp:Button ID="upload" runat="server" Text="GO" OnClick="btn_Click" /><br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<script runat="server">
protected void btn_Click(object sender, EventArgs e)
{
    if (FileUpload1.HasFile)
    {
        string fileExt =
           System.IO.Path.GetExtension(FileUpload1.FileName);

        if (fileExt == ".mp3")
        {
            try
            {
                FileUpload1.SaveAs(Server.MapPath("~/Uploads/" +
                   FileUpload1.FileName));
                Label1.Text = "File name: " +
                    FileUpload1.PostedFile.FileName + "<br>" +
                    FileUpload1.PostedFile.ContentLength + " kb<br>" +
                    "Content type: " +
                    FileUpl开发者_开发问答oad1.PostedFile.ContentType;
            }
            catch (Exception ex)
            {
                Label1.Text = "ERROR: " + ex.Message.ToString();
            }
        }
        else
        {
            Label1.Text = "Only .mp3 files allowed!";
        }
    }
    else
    {
        Label1.Text = "You have not specified a file.";
    }
}



    </script>


Increase the http maxRequestLength using following in your web.config - it should work then. By default it's limited at 4mb.

<system.web>
  <httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜