高分请高手帮忙排忧解难,在线等候!!!! 在上传文件时出错了,报的错没有详细信息,只是一个上不了网时开网页的样子。弄了一天,头都晕了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); } 有可能是上传速度的原因吧,第一次点的时候还没有上传完,你接着又点吧参考一下: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 你的HTTP上传的文件大小是多少?如果超过web.config里面的设置就会出现网页出错的现象。你换一个小一点的文件试试。 楼上的兄弟好像是你说的原因,怎么在Web.config里面设置上传文件的大小呢? 问个简单的Cookie操作 dropdonwlist控件如何不刷新页面 急...kindeditor-4.1.1 怎么给文本框赋值 关于Stream 如何给SQL数据表添加一个临时字段,并给它赋值?? 请教SESSION封装问题 treeview控件 国内的下载地址 模糊查询c#的写法急,sql server查询分析器里能够实现就是程序里面不知道怎么传输变量 界面上简单的判断 DataGrid中如何为某列设置链接啊 关于命名空间的小问题,解决马上给分 怎么获取当前文件夹的名字???
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);
}
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
你换一个小一点的文件试试。