重命名C#.NET文件时,它是通过文件上传控制上传和数据库保存的文件名昌 [英] Rename file in c#.net when its is uploaded through file upload control and save chang name of file in database
问题描述
我有文件上传,通过它我浏览文件
和strore的字符串变量浏览文件名。
现在我想重新命名与存储在另一个字符串变量的另一个名字这个uplaod文件名
I have file uploader through which i browse file and strore the name of of browse file in string variable . now i want rename this uplaod file name with another name which stored in another string variable
string strRoleValue = ddlrole.SelectedValue;
string strfilename = FileUpload1.FileName;
string existpath = Server.MapPath("~\\JD\\");
DirectoryInfo ObjSearchFile = new DirectoryInfo(existpath);
string saveLocation = existpath + strfilename;
FileUpload1.SaveAs(saveLocation);
strRoleValue此变量包含与我想用重命名文件上传,通过上传的文件名。
通过文件名保存在 strfilename
FileUpload控件上传。
所以指定的文件夹保存在此文件之前,
我想它的价值strRoleValue重命名。
我如何能实现this..plz帮助
strRoleValue this variable contains the name with which i want use to rename a file uploaded through fileupload.
filename uploaded through fileupload control stored in strfilename
.
so before saving this file in specified folder
i want to rename it with strRoleValue value.
how can i achieve this..plz help
推荐答案
您可以看看下面的链接
<一个href=\"http://asp-net-example.blogspot.in/2009/01/aspnet-fileupload-example-how-to-rename.html\">http://asp-net-example.blogspot.in/2009/01/aspnet-fileupload-example-how-to-rename.html
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e) {
string uploadFolder = Request.PhysicalApplicationPath + "UploadFile\\";
if (FileUpload1.HasFile)
{
string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(uploadFolder + "Test"+ extension);
Label1.Text = "File uploaded successfully as: " + "Test"+ extension;
}
else
{
Label1.Text = "First select a file.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net FileUpload example: how to rename file when upload (change file name when upload)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Green">asp.net FileUpload example: File Rename</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="OrangeRed"
>
</asp:Label>
<br /><br />
<asp:FileUpload
ID="FileUpload1"
runat="server"
BackColor="DeepPink"
ForeColor="AliceBlue"
/>
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="DeepPink"
OnClick="Button1_Click"
Text="Upload It"
/>
</div>
</form>
</body>
</html>
这篇关于重命名C#.NET文件时,它是通过文件上传控制上传和数据库保存的文件名昌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!