| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 658 人关注过本帖
标题:上传文件出错问题?
只看楼主 加入收藏
iceqier
Rank: 1
等 级:新手上路
威 望:1
帖 子:129
专家分:0
注 册:2006-1-22
收藏
 问题点数:0 回复次数:3 
上传文件出错问题?

我在file1.PostedFile.SaveAs(path);这里出错。为什么。。。
异常详细信息: System.UnauthorizedAccessException: 对路径“c:\inetpub\wwwroot\图片上传\photo”的访问被拒绝。
程序如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace 图片上传
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile file1;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void Button1_Click(object sender, System.EventArgs e)
{
string path=System.IO.Path.Combine(Server.MapPath("."),"photo");
this.Response.Write(path);
bool jpg=file1.Value.ToLower().EndsWith("jpg");
bool gif=file1.Value.ToLower().EndsWith("gif");
if(this.file1.Value.Length==0)
{
this.Response.Write("<script>alert('请选择您要上传的图片文件');</script>");
return;
}
if(jpg==false && gif==false)
{
this.Response.Write("<script>alert('上传的图片格式只能是.jpg或.gif');</script>");
return;
}
if(file1.PostedFile.ContentLength>5120)
{
this.Response.Write("<script>alert('图片的大小不能大于5K');</script>");
return;
}
if(file1.PostedFile.ContentLength !=0)
{
file1.PostedFile.SaveAs(path);
this.Response.Write("<script>alert('图片上传成功!');</script>");
this.Response.Write("123");
}
}
}
}

[此贴子已经被作者于2006-11-3 21:25:54编辑过]

搜索更多相关主题的帖子: using System Web 文件 Drawing 
2006-11-03 21:24
小海龟
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1068
专家分:4
注 册:2006-8-1
收藏
得分:0 
是不是文件夹权限的问题啊?

[bc09] 犯强汉者,虽远比诛!
2006-11-03 21:58
iceqier
Rank: 1
等 级:新手上路
威 望:1
帖 子:129
专家分:0
注 册:2006-1-22
收藏
得分:0 
我把这个项目放到了F盘下面,然后新建个虚似目录就可以了,不知道为什么

天天摸键盘,整天看代码。。。 E-mail : iceqier520@
2006-11-03 22:22
メ冰枫ぱ雪
Rank: 1
等 级:新手上路
威 望:2
帖 子:326
专家分:0
注 册:2004-11-13
收藏
得分:0 
NTFS 的分区吧? 把权限设置成 Everyone

动态网页技术交流群:16449874 免费网络收藏夹:http:///Favorite
2006-11-03 22:40
快速回复:上传文件出错问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011818 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved