问题描述:
在本机上测试上传附件成功,但放到服务器上就总是出现“附件上传失败”提示。服务器环境为:windows server 2003,oracle 9i.
-------------------------------------
上传附件代码如下:
//上传附件,限制大小为20M以内
protected void btnsave_Click(object sender, EventArgs e)
{
Boolean fileOK = false;
String path = Server.MapPath("~/wlgw/");
if (this.dlCon.Items.Count > 0)
{
if (((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).HasFile)
{
String fileExtension = System.IO.Path.GetExtension(((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName).ToLower();
String[] allowedExtensions = { ".gif", ".jpeg", ".jpg",".txt", ".rar" ,".zip"};
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i]&&((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileContent.Length <= 1024*1024*20)
{
fileOK = true;
}
}
}
} if (fileOK)
{
try
{
((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).PostedFile.SaveAs(path
+ ((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName);
((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "上传成功!"; }
catch (Exception ex)
{
((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "上传失败!";
}
}
else
{
((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "请检查文件格式和文件大小!";
}
//listbox接受FileUpload1传过来的文件名称
((ListBox)this.dlCon.Items[0].FindControl("lst")).Items.Insert(0,((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName); }
-----------------------------------------
下载附件代码如下:
protected void btnDownload_Click(object sender, EventArgs e)
{
string strFileUpladPath = Server.MapPath("~/wlgw/");
////从列表框中读取选择的文件
string strFileName = ((ListBox)this.dlCon.Items[0].FindControl("lst")).SelectedValue;
if (strFileName != null && strFileName !="")
{ ////组合成物理路径
string strFilePhysicalPath = strFileUpladPath + strFileName;
//调用另存为对话框
FileDownload(strFilePhysicalPath);
}
else
{
Response.Write("<script language='JavaScript'>alert('请选择附件!');</script>"); }
}
在本机上测试上传附件成功,但放到服务器上就总是出现“附件上传失败”提示。服务器环境为:windows server 2003,oracle 9i.
-------------------------------------
上传附件代码如下:
//上传附件,限制大小为20M以内
protected void btnsave_Click(object sender, EventArgs e)
{
Boolean fileOK = false;
String path = Server.MapPath("~/wlgw/");
if (this.dlCon.Items.Count > 0)
{
if (((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).HasFile)
{
String fileExtension = System.IO.Path.GetExtension(((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName).ToLower();
String[] allowedExtensions = { ".gif", ".jpeg", ".jpg",".txt", ".rar" ,".zip"};
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i]&&((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileContent.Length <= 1024*1024*20)
{
fileOK = true;
}
}
}
} if (fileOK)
{
try
{
((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).PostedFile.SaveAs(path
+ ((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName);
((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "上传成功!"; }
catch (Exception ex)
{
((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "上传失败!";
}
}
else
{
((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "请检查文件格式和文件大小!";
}
//listbox接受FileUpload1传过来的文件名称
((ListBox)this.dlCon.Items[0].FindControl("lst")).Items.Insert(0,((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName); }
-----------------------------------------
下载附件代码如下:
protected void btnDownload_Click(object sender, EventArgs e)
{
string strFileUpladPath = Server.MapPath("~/wlgw/");
////从列表框中读取选择的文件
string strFileName = ((ListBox)this.dlCon.Items[0].FindControl("lst")).SelectedValue;
if (strFileName != null && strFileName !="")
{ ////组合成物理路径
string strFilePhysicalPath = strFileUpladPath + strFileName;
//调用另存为对话框
FileDownload(strFilePhysicalPath);
}
else
{
Response.Write("<script language='JavaScript'>alert('请选择附件!');</script>"); }
}
解决方案 »
- jQuery获取高度的问题,用的是juqery最新版本
- 在ASP.NET里插入FLASH不能显示,老是说未能加载影片,这是怎么回事?
- DataListk中FindControl
- 如何让panel在页面中间的位置
- 取img中的src,求正则??
- 急!图片预加载!
- 刚做的网站,不懂美工,请大家给点建议,帮忙找哈漏洞啊
- 在哪里可以修改admin的PASSWORD
- 微软人俱乐部
- DropDownList帮定使需要设置那几个属性?在C#中和Html中的两种方法?
- |zyciis| 200分求 如何从一个未知的System.Collections.Generic.List<UserInfo>转换为System.Data.DataSet,再转回去
- DataSet类型化数据集
CuteWebUI.AjaxUploader
<httpRuntime executionTimeout="36000" maxRequestLength="2097151" useFullyQualifiedRedirectUrl="false"/>
</system.web>
不行再去问空间提供商.