文件上传到服务器无法浏览,怎么解决啊

jckzhang 2009-04-16 07:45:43
...全文
90 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yxl_QXZD1119 2009-04-16
  • 打赏
  • 举报
回复
fileupload控件


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnUPload_Click(object sender, EventArgs e)
{
//文件路径
string filepath = this.FileUpload1.PostedFile .FileName;
//文件名
string fileName = filepath.Substring(filepath.LastIndexOf("\\") + 1);
//文件扩展名
string fileExtName = filepath.Substring(filepath.LastIndexOf(".") + 1);
//文件名
string filenm = this.FileUpload1.FileName.ToString();
//文件大小
string fileSize = this.FileUpload1.PostedFile.ContentLength.ToString();
//文件类型
string fileType = this.FileUpload1.PostedFile.ContentType.ToString();
//设置你要上传的路径
string upfilePath = Server.MapPath("upfile/") + fileName;
if (filepath == "")
{
Response.Write("<script>alert('请选择一个文件!')</script>");
this.FileUpload1.Focus();
}
else
{
if (fileExtName == "jpg" || fileExtName == "bmp" || fileExtName == "gif" || fileExtName == "pgn")
{
if (int.Parse(fileSize) > 1024 * 1024) //大小可以改
{
Response.Write("<script>alert('文件太大!')");
this.FileUpload1.Focus();
}
else
{
//保存文件
this.FileUpload1.PostedFile.SaveAs(upfilePath);
this.Image1.Visible = true;
this.Image1.ImageUrl = "upfile/" + fileName;
Response.Write("<script>alert('文件上传成功!')</script>");
}
}
else
{
Response.Write("<script>alert('文件扩展名有错,请重新上传!')</script>");
this.FileUpload1.Focus();
this.Image1.Visible = false;
}
}
jckzhang 2009-04-16
  • 打赏
  • 举报
回复

<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<connectionStrings>
<add name="conn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\db.mdb"/>
</connectionStrings>
<appSettings>
<add key="FCKeditor:BasePath" value="~/FCKeditor/"/>
<add key="FCKeditor:UserFilesPath" value="~/userfiles/"/>
</appSettings>
<system.web>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
validate="false" />
</httpHandlers>
<compilation debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>
</compilation>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="None"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。

<customErrors mode="off" defaultRedirect="index.aspx">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>


这个配置文件有错误吗?
快40的码农 2009-04-16
  • 打赏
  • 举报
回复
看看网站版本

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧