如何为.net中的export excel指定saveAs对话框的默认路径

时间:2014-09-29 23:07:34

标签: .net excel export closedxml

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", sheetName.Replace(" ", "_")));

using (var memoryStream = new MemoryStream())
{
    wb.SaveAs(memoryStream);
    memoryStream.WriteTo(HttpContext.Current.Response.OutputStream);
    memoryStream.Close();
}

HttpContext.Current.Response.End();

我想要SaveAs对话框显示默认指定路径,例如c:\ users \ joe \或将文件保存在指定目录中?我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

您可以尝试为Application对象设置DefaultFilePath

wb.Application.DefaultFilePath = @"c:\users\joe";

来源:How to: Get and Set the Default File Path for Workbooks