在上传文件时出错了,报的错没有详细信息,只是一个上不了网时开网页的样子。弄了一天,头都晕了。

解决方案 »

  1.   

    string strFileName = Path.GetFileName(UploadFile.PostedFile.FileName);
    if(ddlType.SelectedIndex==0)
    {
    Response.Write("<script>alert('请选择歌曲的类别!')</script>");
    return;
    }
    if(txtName.Text=="")
    {
    Response.Write("<script>alert('请输入歌手的名字!')</script>");
    return;
    }
    try 
    {
    UploadFile.PostedFile.SaveAs(Path.Combine(Server.MapPath("../music"),strFileName));
    MyDataAccess mda=new MyDataAccess("../");
    string strSQL = "insert into music(musicName,singer,musicPath,MusicType,dt)values('" + Path.GetFileNameWithoutExtension(strFileName) + "','" + txtName.Text.ToString() + "','" + strFileName + "','" + ddlType.SelectedItem.Text.ToString() + "','" + DateTime.Now + "')";
    mda.MyExecute(strSQL);
    string str="music_main.aspx";
    string script = string.Format(@"<script language=javascript> alert('音乐上传成功!'); window.location.href='{0}';</script>",str);
    Response.Write(script); }
    catch(Exception exc)
    {
    Response.Write(exc.Message);
    }
      

  2.   

    有可能是上传速度的原因吧,第一次点的时候还没有上传完,你接着又点吧参考一下:
    1.
             <INPUT id="WebFile" style="WIDTH: 490px; HEIGHT: 22px" type="file" size="62" name="WebFile" runat="server">
    protected System.Web.UI.HtmlControls.HtmlInputFile WebFile;
    文件上传参考代码:
    /// <summary>
    /// 文件上传
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void BtnUpload_Click(object sender, System.EventArgs e)
    {
    if(WebFile.PostedFile.FileName=="")
    {
    Info.Text="请先选择要上传的文件";
    return;
    } try
    {
    char[] spliter = {'\\'};
    string [] FileName = WebFile.PostedFile.FileName.Split(spliter,10); string FullPath = CurrentPath + @"\" + FileName[FileName.Length-1];  //生成完整文件名
    WebFile.PostedFile.SaveAs(FullPath);  //保存文件
    LoadDir(CurrentPath);  //重新载入当前目录
    }
    catch
    {
    Info.Text="上传文件失败,请与管理员联系";
    }
    }2.
     http://www.gdcic.net/dotnetBank/ViewContent.aspx?artid=000000000186
      

  3.   

    你的HTTP上传的文件大小是多少?如果超过web.config里面的设置就会出现网页出错的现象。
    你换一个小一点的文件试试。
      

  4.   

    楼上的兄弟好像是你说的原因,怎么在Web.config里面设置上传文件的大小呢?