文件上传到服务器上,一般存在什么地方?怎么上传? 上次有人说存放在App_Data这个文件夹里?还有就是,用上传控件得到的参数是文件在本地电脑上的存放路径,怎么上传到服务器上?谢谢各位! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 上传文件 /// </summary> /// <param name="FU_Small"></param> /// <param name="UploadPath"></param> /// <returns></returns> public static string UpFile(FileUpload FU_Small, string UploadPath) { Boolean fileOK = false; string newname = GenerateFileName(); //生成文件名 String fileExtension = System.IO.Path.GetExtension(FU_Small.PostedFile.FileName).ToLower(); //获得扩展名 if (FU_Small.PostedFile.ContentLength < CnoolGlobal.FileMaxSize)//文件大小是否超标 { //不超标 if (FU_Small.HasFile)//文件存在 { String[] allowedExtensions = { ".doc", ".rar", ".txt", ".xls" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } else return "没有文件"; //文件没有上传 if (fileOK) { try { FU_Small.PostedFile.SaveAs(UploadPath + newname + fileExtension); return (newname + fileExtension); } catch { return "上传出错"; //文件上传失败 } } else return "格式不对"; //文件格式不正确 } else return "超过限制大小"; } 由你设定File1.PostedFile.SaveAs("服务器路径"); 很簡單.用FileUpLoad控件.這個是取得路徑並把要上傳的文件保存到b2b_Excel中.private string Getpath() { string str_name = File_Upload.FileName; string str_Type = str_name.Substring(str_name.LastIndexOf(".") + 1); string str_ipath = Server.MapPath("b2b_Excel") + "\\" + str_name; string str_fpath = "b2b_Excel" + "\\" + str_name; if (str_Type == "xls") { try { File_Upload.SaveAs(str_ipath); return str_ipath; } catch (Exception ex) { //throw new Exception (ex.Message); System.Windows.Forms.MessageBox.Show("文件路徑不存在,請重新選擇!"); } } else { return ""; } return str_ipath; } File1.PostedFile.SaveAs("服务器路径"); File1.PostedFile.SaveAs("服务器路径");由你自己设置 使用<asp:FileUpload ID="FileUpload1" runat="server" />控件可以在新建网站里面自己创建一个文件夹比如文件夹名为UpLoadif (FileUpload1.HasFile) { FileUpload1.SaveAs(Server.MapPath("UpLoad/") + FileUpload1.FileName); Image1.ImageUrl = "UpLoad/" + FileUpload1.FileName; Image1.Visible = true; } 页面上有几十个textbox,如何弄成数组,方便赋值和保存? json字符串片段转换成HTML片段字符串的问题. wap 页面标签tab顺序问题 谁有 ip 库,能否给我一个! 如何使自身页面最大化,并且隐藏IE的菜单和工具栏? aspnet_compiler 具体怎么用? 用户'NT AUTHORITY\NETWORK SERVICE' 登录失败 DataGrid 如何非绑定添加数据? FreeTextBox的问题(急) asp.net mvc3先上图,否则说不清楚 求教如何做到像firefox中的一个功能!高手进来。 NavigateUrl里的&符号
/// 上传文件
/// </summary>
/// <param name="FU_Small"></param>
/// <param name="UploadPath"></param>
/// <returns></returns>
public static string UpFile(FileUpload FU_Small, string UploadPath)
{ Boolean fileOK = false; string newname = GenerateFileName(); //生成文件名 String fileExtension = System.IO.Path.GetExtension(FU_Small.PostedFile.FileName).ToLower(); //获得扩展名 if (FU_Small.PostedFile.ContentLength < CnoolGlobal.FileMaxSize)//文件大小是否超标
{
//不超标
if (FU_Small.HasFile)//文件存在
{
String[] allowedExtensions = { ".doc", ".rar", ".txt", ".xls" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
else
return "没有文件"; //文件没有上传 if (fileOK)
{
try
{
FU_Small.PostedFile.SaveAs(UploadPath
+ newname + fileExtension);
return (newname + fileExtension);
}
catch
{
return "上传出错"; //文件上传失败
} }
else
return "格式不对"; //文件格式不正确 }
else
return "超过限制大小";
}
File1.PostedFile.SaveAs("服务器路径");
private string Getpath()
{
string str_name = File_Upload.FileName;
string str_Type = str_name.Substring(str_name.LastIndexOf(".") + 1);
string str_ipath = Server.MapPath("b2b_Excel") + "\\" + str_name;
string str_fpath = "b2b_Excel" + "\\" + str_name;
if (str_Type == "xls")
{
try
{
File_Upload.SaveAs(str_ipath);
return str_ipath;
}
catch (Exception ex)
{
//throw new Exception (ex.Message);
System.Windows.Forms.MessageBox.Show("文件路徑不存在,請重新選擇!");
}
}
else
{
return "";
}
return str_ipath;
}
由你自己设置
可以在新建网站里面自己创建一个文件夹比如文件夹名为UpLoadif (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("UpLoad/") + FileUpload1.FileName);
Image1.ImageUrl = "UpLoad/" + FileUpload1.FileName;
Image1.Visible = true;
}