我如何...重命名上传的文件 [英] How do I...Rename an Uploaded File
本文介绍了我如何...重命名上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Guys,请将此文件复制到指定的文件夹后重命名。我需要重命名为文本框中的值。我非常感谢你的帮助。
private void UploadPassportbutton_Click( object sender,EventArgs e)
{
// 打开文件对话框
OpenFileDialog getPassport = new OpenFileDialog() ;
getPassport.Multiselect = false ;
getPassport.Title = 选择护照照片;
// 图片过滤器
getPassport.Filter = 图像文件(* .png; * .PNG)| * .png; * .PNG;
if (getPassport.ShowDialog()== DialogResult.OK)
{
// 设置新文件路径
string newPath = Path.Combine( @ \\QUBE \Pics \,Path.GetFileName(getPassport.FileName) );
PassportpictureBox.Image = Image.FromFile(getPassport.FileName);
// 检查文件是否存在
if (File.Exists(newPath))
{
// 您可以重命名文件
MessageBox.Show( 该图像已存在。 .., this .Text,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
File.Copy(getPassport.FileName,newPath);
}
}
解决方案
只需使用
File.Move(currentPath,newPath);
http://msdn.microsoft.com/en-us/library/system.io.file.move(v = vs.110)的.aspx 一> [ ^ ]
Hello Guys, please I need to rename this file after it has been copied to the folder specified. I need to be renamed to a value inside a textbox. I would really appreciate your help.
private void UploadPassportbutton_Click(object sender, EventArgs e)
{
// open file dialog
OpenFileDialog getPassport = new OpenFileDialog();
getPassport.Multiselect = false;
getPassport.Title = "Select Passport Photograph";
// image filters
getPassport.Filter = "Image Files(*.png; *.PNG)|*.png; *.PNG";
if (getPassport.ShowDialog() == DialogResult.OK)
{
//sets the new file path
string newPath = Path.Combine(@"\\QUBE\Pics\", Path.GetFileName(getPassport.FileName));
PassportpictureBox.Image = Image.FromFile(getPassport.FileName);
//check if fileexists
if (File.Exists(newPath))
{
//You could rename the file
MessageBox.Show("That image already exists...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
File.Copy(getPassport.FileName, newPath);
}
}
解决方案
Just use
File.Move(currentPath, newPath);
http://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx[^]
这篇关于我如何...重命名上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文