基本上我试图从C#web应用程序创建和导出.ics文件,以便用户可以保存它,并在Outlook中打开它以添加一些内容到他们的日历。从.NET Web应用程序导出到Outlook(.ics文件)
这是我目前所面对的代码...
string icsFile = createICSFile(description, startDate, endDate, summary);
//Get the paths required for writing the file to a temp destination on
//the server. In the directory where the application runs from.
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
string assPath = Path.GetDirectoryName(path).ToString();
string fileName = emplNo + "App.ics";
string fullPath = assPath.Substring(0, assPath.Length-4);
fullPath = fullPath + @"\VTData\Calendar_Event\UserICSFiles";
string writePath = fullPath + @"\" + fileName; //writepath is the path to the file itself.
//If the file already exists, delete it so a new one can be written.
if (File.Exists(writePath))
{
File.Delete(writePath);
}
//Write the file.
using (System.IO.StreamWriter file = new System.IO.StreamWriter(writePath, true))
{
file.WriteLine(icsFile);
}
上述作品完美。它写入文件并首先删除所有旧文件。
我的主要问题是如何让它给用户?
我试过页面重定向直奔文件的路径:
Response.Redirect(writePath);
它不工作,并抛出以下错误:
htmlfile: Access is denied.
注意:如果我复制和粘贴内容writePath
,并将其粘贴到Internet Explorer中,保存文件对话框打开并允许我下载.ics文件。
我也试着提示保存对话框,下载文件,
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "inline; filename=" + fileName + ";");
response.TransmitFile(fullPath);
response.Flush(); // Error happens here
response.End();
它也不管用。
Access to the path 'C:\VT\VT-WEB MCSC\*some of path omitted *\VTData\Calendar_Event\UserICSFiles' is denied.
再次访问被拒绝错误。
可能是什么问题?
顺便说一句,没有“C#.NET”这样的东西。该语言被命名为“C#”。 – 2011-06-01 18:33:08