<asp:FileUpload ID="FileUpload1" runat="server" />在vs2008中rj提交上传就显示无法访问,没有执行事件就没了
解决方案 »
- ASP.NET中主要有哪些用于显示的数据控件?目前网站最常用的有哪些?
- MVC分享到的代码怎么写?
- primarykey 2个字段问题(C#)~~~~~~~~~可行马上结帐,在线等
- 在图片上传得时候出现这样的错误是怎么回事啊,救急啊! 我用GridView绑定商品的部分信息,当点击删除的时候总是出现下面的错误是怎么
- CSDN里打开问题的页面后有个回复框,当没有登陆的时候就不显示,当登陆了后就显示出来,请问这个功能是这么做的吗?
- HTML代码存入数据库的问题
- 没分了,帐号会不会被注销掉?
- 请教:服务器端定时操作的问题
- winform嵌入webform中时,如何让它在客户端安装,而不用每次打开都要下载一次?
- 如何使一个控件充满整页?
- 网站被攻击,大家帮忙测试一下,看看漏洞存在哪里?
- 如何向xml存入多行数据
/// <param name="FileUpload1">FileUpload上传控件</param>
/// <param name="filesize">自定义的要上传文件的最大大小</param>
/// <param name="CurrFileSize">上传文件的实际大小</param>
/// <param name="CurrFileType">上传文件的类型</param
/// <param name="types">参数(0为只上传图片,1只能上传视频和Flash)</param>
/// <returns>返回一个ArrayList类(文件保存库的相对路径,文件的大小和文件类型)</returns>
public static ArrayList UploadFile(System.Web.UI.WebControls.FileUpload FileUpload1, int filesize, string Pathfile, int types)
{
ArrayList list = new ArrayList();
int filetype = 0;
string CurrFileSize = "";
string CurrFileType = "";
if (FileUpload1.FileName != "")
{
Page pages = new Page();
string name = FileUpload1.FileName;//文件名称
string size = FileUpload1.PostedFile.ContentLength.ToString();//文件大小
string type = FileUpload1.PostedFile.ContentType;//文件类型
//Path.GetExtension(name);//指定字符串的扩展名 .exe
string type2 = name.Substring(name.LastIndexOf(".") + 1);//文件扩展名
//if (!Directory.Exists(pages.Server.MapPath("../"+Pathfile) + "\\"))//判断该文件夹是否存在
//{
// Directory.CreateDirectory(pages.Server.MapPath("../"+Pathfile) + "\\");
//}
string ipath = pages.Server.MapPath("../" + Pathfile) + "\\" + name;//-----------文件上传服务器的路径
string wpath = Pathfile + "/" + name;//返回将在保存在数据库的相对路径的字符串
string ipath1 = pages.Server.MapPath(Pathfile) + "\\" + name;//-----------文件上传服务器的路径
if (Convert.ToInt32(size) > filesize)
{
CurrFileSize = "";
CurrFileType = "";
list.Add(1);
list.Add(size);//加载实际大小
list.Add(filetype);//类型标识
return list;
}
else
{
#region *****************************
if (types == 0)//只能上传图片
{ if (type2 == "jpg" || type2 == "gif" || type2 == "png")
{
string FileDateName = DateTime.Now.ToString().Replace(":", "").Replace(" ", "").Replace("-", "");//截取后的时间字符串
string FileExtenstion = Path.GetExtension(name);//文件的扩展名
name = FileDateName + FileExtenstion;//如果文件类型为图片类型,对文件名进行更改(如:200905152315.jpg)
ipath = pages.Server.MapPath("../" + Pathfile + "/" + name);//(要保存的路径)
filetype = 0;
FileUpload1.SaveAs(ipath);//保存路径上传到服务器
CurrFileSize = size;//返回文件的大小
CurrFileType = type2;//返回文件的类型
list.Add(3);
list.Add(Pathfile + "/" + name);
list.Add(CurrFileSize);
list.Add(CurrFileType);
list.Add(filetype);
return list;
}
else
{
CurrFileSize = "";
CurrFileType = "";
list.Add(2);//标识符
list.Add(type2);
list.Add(filetype);
return list;
}
}
else if (types == 1)//只能上传视频
{
if (type2 == "flv")
{
filetype = 1;
FileUpload1.SaveAs(ipath);//保存路径上传到服务器
CurrFileSize = size;//返回文件的大小
CurrFileType = type2;//返回文件的类型
list.Add(3);
list.Add(wpath);
list.Add(CurrFileSize);
list.Add(CurrFileType);
list.Add(filetype);
return list;
}
else
{
CurrFileSize = "";
CurrFileType = "";
list.Add(2);//标识符
list.Add(type2);
list.Add(filetype);
return list;
}
}
else if (types == 2)//只能上传视频
{
if (type2 == "txt" || type2 == "doc" || type2 == "docx")
{
filetype = 2;
FileUpload1.SaveAs(ipath1);//保存路径上传到服务器
CurrFileSize = size;//返回文件的大小
CurrFileType = type2;//返回文件的类型
list.Add(3);
list.Add(wpath);
list.Add(CurrFileSize);
list.Add(CurrFileType);
list.Add(filetype);
return list;
}
else
{
CurrFileSize = "";
CurrFileType = "";
list.Add(2);//标识符
list.Add(type2);
list.Add(filetype);
return list;
}
}
else
{
CurrFileSize = "";
CurrFileType = "";
return null;
}
#endregion
}
}
else
{
CurrFileSize = "";
CurrFileType = "";
return null;
} #region
// if (type2 == "jpg" || type2 == "gif" || type2 == "png" || type2 == "doc" || type2 == "rar" || type2 == "txt" || type2 == "xls" || type2 == "wmv" || type2 == "swf")//指定文件上传的格式
// {
// if (type2 == "jpg" || type2 == "gif" || type2 == "png")
// {
// string FileDateName = DateTime.Now.ToString().Replace(":", "").Replace(" ", "").Replace("-", "");//截取后的时间字符串
// string FileExtenstion = Path.GetExtension(name);//文件的扩展名
// name = FileDateName + FileExtenstion;//如果文件类型为图片类型,对文件名进行更改(如:200905152315.jpg)
// ipath = pages.Server.MapPath("../"+Pathfile+"/" + name);//(要保存的路径)
// filetype = 0;
// }
// if ( type2 == "wmv" || type2 == "swf")
// {
// filetype = 1;
// }
// else
// {
// filetype = 2;
// }
// FileUpload1.SaveAs(ipath);//保存路径上传到服务器
// CurrFileSize = size;//返回文件的大小
// CurrFileType = type2;//返回文件的类型
// list.Add(3);
// list.Add(wpath);
// list.Add(CurrFileSize);
// list.Add(CurrFileType);
// list.Add(filetype);
// return list ;
// }
// else
// {
// CurrFileSize = "";
// CurrFileType = "";
// list.Add(2);//标识符
// list.Add(type2);
// list.Add(filetype);
// return list;
// }
// }
//}
//else
//{
// CurrFileSize = "";
// CurrFileType = "";
// return null;
//}
#endregion
}
#endregion
#region 文件上传并以流的形式存到数据库中
/// <summary>
///
/// </summary>
/// <param name="FileUpload1"></param>
/// <param name="filesize"></param>
/// <param name="ArrayByte"></param>
/// <returns></returns>
public static ArrayList UploadFile(System.Web.UI.WebControls.FileUpload FileUpload1, int filesize, out byte[] ArrayByte)
{
ArrayList list = new ArrayList();
string CurrenSize = FileUpload1.PostedFile.ContentLength.ToString();
string CurrenType = FileUpload1.PostedFile.ContentType;
string type2 = FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1);
if (FileUpload1.FileName != "")
{
if (int.Parse(CurrenSize) > filesize)
{
list.Add(1);
list.Add(CurrenSize);
ArrayByte = null;
return list;
}
else
{
if (type2 == "jpg" || type2 == "gif" || type2 == "png" || type2 == "doc" || type2 == "rar" || type2 == "txt" || type2 == "xls")//指定文件上传的格式
{
ArrayByte = FileUpload1.FileBytes;//获得文件流并写入数组中
//或者这样写入流
// Stream st= FileUpload1.PostedFile.InputStream;
//将流读到数组中`
// int i = st.Read(ArrayByte, 0, st.Length);
list.Add(3);
list.Add(CurrenSize);
list.Add(CurrenType);
return list;
}
else
{
list.Add(2);//标识符
list.Add(type2);
ArrayByte = null;
return list;
}
}
}
else
{
ArrayByte = null;
return null;
}
}
用asp:buttom按钮驱动这个方法
一点上传就出错:找不到服务器
奇怪你们不会嘛
如果上传图片就没问题