在这种方法中,我将一个 excel 文件保存在该路径的目录中,而不是写入整个路径,有没有办法让它变短,以便它自动保存在调试文件中?
using (var file = File.Open("C:\Users\john\Documents\Visual Studio 2015\Projects\EXCEl PROJECT\webform\" + filename + ".xlsx",FileMode.Create))
{
ms.WriteTo(file); // copy the memory stream to the file stream
}
使用此属性作为基目录。您可以根据需要附加到它。 System.AppDomain.CurrentDomain.BaseDirectory
样本:
using (var file = File.Open(AppDomain.CurrentDomain.BaseDirectory + "\webform\" + filename + ".xlsx", FileMode.Create))
{
ms.WriteTo(file); // copy the memory stream to the file stream
}