更改上载图像的名称. [英] Change the name of Uploaded Image..
本文介绍了更改上载图像的名称.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在每次通过Fileupload控件上传图像时更改图像的名称.
我已经使用了一个fileuploader,文本框和一个保存按钮控件.
evrytime我在保存"按钮上输入,图像文件被保存,但按其原始名称
这是我的问题
我想将上传的图像文件的名称更改为我在文本框中输入的名称.怎么可能,求救!!
我的代码:
I want to change the name of image everytime i upload it by Fileupload control.
i have taken one fileuploader ,textbox and a save button control.
evrytime i enter on save button the image file gets saved but by its original name
Here is my Problem
i want to change the name of the uploaded image file to the name i have entered in the textbox. How is it possible, Help!!
My Code:
protected void savebtn_Click(object sender, EventArgs e)
{
strFileName = "~/album/" "/" + FileUpload1.FileName.ToString();
FileUpload1.PostedFile.SaveAs(Server.MapPath(strFileName ));
}
}
推荐答案
http://forums.asp.net/t/1121501.aspx [ ^ ]
希望以上信息对您有所帮助.如果您还有其他疑问,请告诉我.
http://forums.asp.net/t/1121501.aspx[^]
I hope the above information will be helpful. If you have more concerns, please let me know.
添加名称空间
Add namespace
using System.IO;
并添加此行以重命名上传的文件.
And add this line to rename the uploaded file.
File.Move(@"~/album/", @"Your_New_File_Path\" + Text1.Text);
try this.
a = Fup1.FileName.Split('.');
fileName1 = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
FilePath = Server.MapPath(@"~\MDAFile");
Fup1.SaveAs(FilePath + @"\" + fileName1);
string filename = FilePath + @"\" + fileName1;
这篇关于更改上载图像的名称.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文