回发后没有获得FileUpLoad的值 [英] not getting value of FileUpLoad after postback
本文介绍了回发后没有获得FileUpLoad的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i有FileUpLoad控件和按钮控件(UpLoadButton)。我已经遇到问题,就像FileUpLoad包含文件路径一样,它显示为null在postBack或UpLoadButton点击后。
我使用了以下代码:
hi all,
i have FileUpLoad Control and Button control (UpLoadButton).I''ve facing problem like though FileUpLoad containg file path,it is showing null once after postBack or UpLoadButton clicked.
i''ve used following code:
protected void btn_UpLoadButton_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.FileName!= null)//here is my doubt that showing Null Value though it''s filled
{
HttpPostedFile File1 = FileUpload1.PostedFile;
Data = new byte[File1.ContentLength];
File1.InputStream.Read(Data, 0, File1.ContentLength);
// Session["ScannedPhotoData"] = Data;
string strFilename = getFilename(FileUpload1.PostedFile.FileName);
string strFilepath = "ImageFolder\\" + strFilename;
string Photo = Server.MapPath(strFilepath);
//if (File.Exists(Photo))
// File.Delete(Photo);
FileUpload1.PostedFile.SaveAs(Photo);
ImgScannedPhoto.ImageUrl = "imageview.aspx?img=" + Photo;
//ScannedPhotoPath.Text = Photo;
}
}
请回复谢谢
please reply thanks
推荐答案
你不能保留FileUpload控件中的值。这是出于安全原因。你可以使用RequiredFieldValidator作为keyname文本框。
You can''t retain value in FileUpload control. This is because of security reasons. you can use RequiredFieldValidator for keyname textbox.
尝试将值保存到会话变量或隐藏字段以保存数据。看看这篇文章。
http://www.ironspeed.com/articles /Maintain%20File%20Upload%20Control/Article.aspx [ ^ ]
Try saving the value to a session variable or a hidden field to preserve the data.Have a look at this article.
http://www.ironspeed.com/articles/Maintain%20File%20Upload%20Control/Article.aspx[^]
if (Fup1.HasFile)
{
string FilePath = "";
string[] a = new string[1];
string fileName = "";
string FullName = "";
try
{
if (Fup1.FileName.Length > 0)
{
a = Fup1.FileName.Split(''.'');
fileName = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
FilePath = Server.MapPath(@"~\FolderName");
Fup1.SaveAs(FilePath + @"\" + fileName);
FullName = FilePath + @"\" + fileName;
// Database Save Operation of filename.
}
}
catch
{
}
}
你可以试试这个。
如果没有解决此错误,请尝试, -
You can try with this.
If with this error is not solved then try,-
FileUploader.Atribute.add("Value",FileUploader.PostedFile);
在PageLoad。
希望这可以帮到你。
In PageLoad.
Hope this can help you.
这篇关于回发后没有获得FileUpLoad的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文