2016-07-07 62 views
0

在这种方法中,我在这条道路保存,而不是写整个路径目录中的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 


      } 
+1

取在为[MapPath方法]看看(https://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath(V = VS 0.110)的.aspx) –

回答

0

将此属性用作基本目录。您可以根据需要追加。 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 
    }