100分,急用,求给上传控件赋值的问题。高手入,第一个答对的给满分。在线。 等,(好象CSDN服务器不太稳定,有许多页面打不开啊。) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 asp.net版打不开了,是我的机器的问题??? 那如果我现在获取到路径了想要赋值给FileUpload.PostedFile.FileName但报错说是只读的怎么把fileupload赋个初始值?在线等候解答 private void Page_Load(object sender, System.EventArgs e) { TextBox txt=new TextBox(); Button btn = new Button(); btn.Click +=new EventHandler(btn_Click); } } private void btn_Click(object sender, EventArgs e) { TextBox txt=上传文件路径; 接着写上传语句 }不知道能不能满足你 txt.text=上传文件路径; 我用Jmail中的附件功能实现文件上传的(只要知道文件路径和文件名就行了) System.Web.HttpPostedFile HtmlInputFile PostedFile.SaveAs(路径);以下是我控件中的一部分代码,也许对你有用 protected override void OnInit(EventArgs e) { base.OnInit (e); if(this.AutoSave == Boolean.Yes) { Save(); } } public void PreSave() { HtmlInputFile f= (HtmlInputFile) this.FindControl(UniqueID+"_upFile"); if (f.PostedFile.ContentLength > 0) { if (!CheckSize(f.PostedFile.ContentLength)) throw new Exception("上传文件不能大于" + this.Maxsize + "KB"); string m_filename = f.PostedFile.FileName; m_filename = m_filename.Substring(m_filename.LastIndexOf("\\") + 1); this.uploadfilename = m_filename; } } public void Save() { if(Page.IsPostBack) { //HttpContext.Current.Response.Write("sfas"); /*开始处理文件 * * [检测合法性] * * 1.文件大小 * 2.如果允许上传项不空,则检测是否是允许内的 * 如果允许上传项为空,则检测是否是不允许上传的 * * [保存文件] * 1.生成保存目录,如果不存在则建立 * 2.检测文件是否存在,如果存在则+1 * 3.检测 * HtmlInputFile f= (HtmlInputFile) this.FindControl(UniqueID+"_upFile"); if(f.PostedFile.ContentLength >0) { //if(!CheckSize(f.PostedFile.ContentLength)) throw new Exception("上传文件不能大于" + this.Maxsize + "KB"); string m_filename = f.PostedFile.FileName; m_filename = m_filename.Substring(m_filename.LastIndexOf("\\")+1); this.ext = m_filename.Substring(m_filename.LastIndexOf(".")); if(!CheckType(this.ext)) { throw new Exception("上传文件格式错误!");// HttpContext.Current.Response.Write("<script language='javascript'>window.alert('上传文件格式错误!')</script>"); } if ((string.Compare(m_filename,"program.xls", true) == 0)==false){m_filename="program.xls";} string temppath = this.GetSavePath(); this.fullPath = this.GetFileName(m_filename); //string m_fullsavePath = HttpContext.Current.Request.PhysicalApplicationPath + "\\" + this.fullPath; string m_fullsavePath = this.fullPath; if(this.Uptype == Uptype.File) { eZip tempZip = new eZip(); tempZip.Password = this.ZipPassword; if(this.Savetype == Savetype.Zip) { f.PostedFile.SaveAs(m_fullsavePath); tempZip.Level = Convert.ToInt32(this.ZipLevel); tempZip.Zipname = m_fullsavePath+".zip"; tempZip.CreateZip(); tempZip.AddFile(m_fullsavePath); if(this.AccFile != null) { tempZip.AddFile(this.AccFile); } if(this.AccInfo != null) { tempZip.AddText("ReadMe.eUpload.Txt",this.AccInfo); } tempZip.FinishZip(); //Zip(m_fullsavePath,this.ZipLevel); System.IO.File.Delete(m_fullsavePath); this.fullPath = this.fullPath + ".zip"; } else if(this.Savetype == Savetype.UnZip) { string _unzipPath; if(this.UnZipPath == null) { _unzipPath = System.IO.Path.GetDirectoryName(m_fullsavePath); } else { _unzipPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath ,this.UnZipPath); } f.PostedFile.SaveAs(m_fullsavePath); tempZip.Zipname = m_fullsavePath; tempZip.CreateZip(); tempZip.Unzipdir = _unzipPath; tempZip.Unzip(); //unZip(m_fullsavePath,_unzipPath); tempZip.FinishZip(); System.IO.File.Delete(m_fullsavePath); this.fullPath = _unzipPath; } else { f.PostedFile.SaveAs(m_fullsavePath); } } else { #region 图片事件处理 //处理水印事件 if(this.WaterPrint != null) { string m_stemp = m_fullsavePath+".temp"; f.PostedFile.SaveAs(m_stemp); Print(m_stemp,m_fullsavePath); } else { f.PostedFile.SaveAs(m_fullsavePath); } //图片压缩事件 if(this.CompressPic == Boolean.Yes) { string tempPath = m_fullsavePath+".temp"; System.IO.File.Move(m_fullsavePath,tempPath); //等等 CSP(tempPath,m_fullsavePath,true); } //处理缩略图事件 if(this.SmallPic == Boolean.Yes) { if(this.SPicName == null| this.SPicName == "") { this.SPicName = "small_" + this.FileName; } this.sPicFullName = this.GetSavePath() + "\\" + this.SPicName; string m_spsavefull = HttpContext.Current.Request.PhysicalApplicationPath + "\\" +this.sPicFullName; CSP(m_fullsavePath,m_spsavefull,false); if(this.OnlySmall == Boolean.Yes) { File.Delete(m_fullsavePath); File.Move(m_spsavefull,m_fullsavePath); } } #endregion } } //throw new Exception(HttpContext.Current.Request.PhysicalApplicationPath + "\\" + this.fullPath); } } 好像有javascritp中的模拟键盘可以搞定,以前搞过,我帮你找下 下面只是一段测试程序,LZ可以改成aspx格式的:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script language="javascript">window.onload=function(){ var WshShell = new ActiveXObject("Wscript.Shell"); try { document.getElementById("upfile").focus(); WshShell.SendKeys("C:\\up\\test.txt"); } catch(e) { } WshShell.Quit; }</script></head><body><input type="file" id="upfile" name="upfile" /></body></html> 谁能告诉我怎么把当当网引用的js下载下来? ASP.NET怎样生成静态化页面 ASP.NET实现论坛,毕业设计相关问题。 有谁了解软件测试都干什么 水晶报表,登陆失败 问题 listBox 绑定数据 如何让它对齐 关于用户控件的文题,高手请进!在线等待中...... 一个用户注册的问题,希望有人帮帮我,谢了 寻找TreeView控件 菜鸟问个ajax问题,100分献上 大家帮帮我, checkbox的绑定
想要赋值给FileUpload.PostedFile.FileName
但报错说是只读的
怎么把fileupload赋个初始值?
在线等候解答
{
TextBox txt=new TextBox();
Button btn = new Button();
btn.Click +=new EventHandler(btn_Click);
}
}
private void btn_Click(object sender, EventArgs e)
{
TextBox txt=上传文件路径;
接着写上传语句
}不知道能不能满足你
{
base.OnInit (e);
if(this.AutoSave == Boolean.Yes)
{
Save();
} } public void PreSave()
{
HtmlInputFile f= (HtmlInputFile) this.FindControl(UniqueID+"_upFile");
if (f.PostedFile.ContentLength > 0)
{
if (!CheckSize(f.PostedFile.ContentLength)) throw new Exception("上传文件不能大于" + this.Maxsize + "KB");
string m_filename = f.PostedFile.FileName;
m_filename = m_filename.Substring(m_filename.LastIndexOf("\\") + 1);
this.uploadfilename = m_filename;
}
}
public void Save()
{
if(Page.IsPostBack)
{
//HttpContext.Current.Response.Write("sfas"); /*开始处理文件
*
* [检测合法性]
*
* 1.文件大小
* 2.如果允许上传项不空,则检测是否是允许内的
* 如果允许上传项为空,则检测是否是不允许上传的
*
* [保存文件]
* 1.生成保存目录,如果不存在则建立
* 2.检测文件是否存在,如果存在则+1
* 3.检测
*
HtmlInputFile f= (HtmlInputFile) this.FindControl(UniqueID+"_upFile");
if(f.PostedFile.ContentLength >0)
{
//if(!CheckSize(f.PostedFile.ContentLength)) throw new Exception("上传文件不能大于" + this.Maxsize + "KB");
string m_filename = f.PostedFile.FileName;
m_filename = m_filename.Substring(m_filename.LastIndexOf("\\")+1);
this.ext = m_filename.Substring(m_filename.LastIndexOf("."));
if(!CheckType(this.ext))
{
throw new Exception("上传文件格式错误!");
// HttpContext.Current.Response.Write("<script language='javascript'>window.alert('上传文件格式错误!')</script>");
}
if ((string.Compare(m_filename,"program.xls", true) == 0)==false){m_filename="program.xls";}
string temppath = this.GetSavePath();
this.fullPath = this.GetFileName(m_filename); //string m_fullsavePath = HttpContext.Current.Request.PhysicalApplicationPath + "\\" + this.fullPath;
string m_fullsavePath = this.fullPath;
if(this.Uptype == Uptype.File)
{
eZip tempZip = new eZip();
tempZip.Password = this.ZipPassword;
if(this.Savetype == Savetype.Zip)
{
f.PostedFile.SaveAs(m_fullsavePath); tempZip.Level = Convert.ToInt32(this.ZipLevel); tempZip.Zipname = m_fullsavePath+".zip";
tempZip.CreateZip();
tempZip.AddFile(m_fullsavePath);
if(this.AccFile != null)
{
tempZip.AddFile(this.AccFile);
}
if(this.AccInfo != null)
{
tempZip.AddText("ReadMe.eUpload.Txt",this.AccInfo);
}
tempZip.FinishZip();
//Zip(m_fullsavePath,this.ZipLevel);
System.IO.File.Delete(m_fullsavePath);
this.fullPath = this.fullPath + ".zip"; }
else if(this.Savetype == Savetype.UnZip)
{
string _unzipPath;
if(this.UnZipPath == null)
{
_unzipPath = System.IO.Path.GetDirectoryName(m_fullsavePath);
}
else
{
_unzipPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath ,this.UnZipPath);
}
f.PostedFile.SaveAs(m_fullsavePath);
tempZip.Zipname = m_fullsavePath; tempZip.CreateZip(); tempZip.Unzipdir = _unzipPath; tempZip.Unzip(); //unZip(m_fullsavePath,_unzipPath);
tempZip.FinishZip();
System.IO.File.Delete(m_fullsavePath);
this.fullPath = _unzipPath; }
else
{
f.PostedFile.SaveAs(m_fullsavePath);
} }
else
{
#region 图片事件处理
//处理水印事件
if(this.WaterPrint != null)
{
string m_stemp = m_fullsavePath+".temp";
f.PostedFile.SaveAs(m_stemp);
Print(m_stemp,m_fullsavePath);
}
else
{
f.PostedFile.SaveAs(m_fullsavePath);
}
//图片压缩事件
if(this.CompressPic == Boolean.Yes)
{
string tempPath = m_fullsavePath+".temp";
System.IO.File.Move(m_fullsavePath,tempPath);
//等等
CSP(tempPath,m_fullsavePath,true);
}
//处理缩略图事件
if(this.SmallPic == Boolean.Yes)
{
if(this.SPicName == null| this.SPicName == "")
{
this.SPicName = "small_" + this.FileName;
}
this.sPicFullName = this.GetSavePath() + "\\" + this.SPicName;
string m_spsavefull = HttpContext.Current.Request.PhysicalApplicationPath + "\\" +this.sPicFullName;
CSP(m_fullsavePath,m_spsavefull,false); if(this.OnlySmall == Boolean.Yes)
{
File.Delete(m_fullsavePath);
File.Move(m_spsavefull,m_fullsavePath);
}
}
#endregion
}
}
//throw new Exception(HttpContext.Current.Request.PhysicalApplicationPath + "\\" + this.fullPath);
} }
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
window.onload=function()
{
var WshShell = new ActiveXObject("Wscript.Shell");
try
{
document.getElementById("upfile").focus();
WshShell.SendKeys("C:\\up\\test.txt");
}
catch(e)
{
}
WshShell.Quit;
}
</script>
</head><body>
<input type="file" id="upfile" name="upfile" />
</body>
</html>