我已经导入了一个excel文件,我想保存在项目中名为excelfiles的文件夹中。现在导入的文件直接存储在项目中。如何映射以将文件保存到文件夹中的excelfile文件夹?我的代码是
protected void importnpatscoew_Click(object sender, EventArgs e)
{
if (fileuploadExcel.HasFile)
{
string FileName = Path.GetFileName(fileuploadExcel.PostedFile.FileName);
string Extension = Path.GetExtension(fileuploadExcel.PostedFile.FileName);
string FolderPath = ConfigurationManager.AppSettings["excelimports"];
string FilePath = Server.MapPath(FolderPath + FileName);
fileuploadExcel.SaveAs(FilePath);
Import_To_Grid(FilePath, Extension, "YES");
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Please select a file first..!!');", true);
}
}
答案 0 :(得分:0)
假设您的项目根名为MyProject,并且您希望在MyProject下保存到文件夹名称,则可以使用
FileUpload.SaveAs("~/ExcelFiles/yourfile.extension")
请注意
~/ resolves to the application root.
/ resolves to the site root.
因此,在您的情况下(应用程序根目录和站点根目录都是MyProject),您也可以使用FileUpload.SaveAs("/ExcelFiles/yourfile.extension")