2014-10-08 67 views
0

我正在進行計劃控制。我需要導出計劃約會。 從下面的代碼中我創建了Test.ics文件在臨時文件夾中,然後複製到新的位置。如何使用保存對話框創建和保存ics文件?

如何在不保存臨時文件夾的情況下保存文件。 是否可以將文件存儲在緩衝區或任何臨時對象中,而不是將其存儲在臨時文件夾中?

請找我下面的代碼片段...

string fileName = "Test.ics"; 
InternetCalendaring.ICSBuilder icsbBuilder = new InternetCalendaring.ICSBuilder(vecVEvents); 
sRes = icsbBuilder.ICSBuildProcess(); 
string FilePath = System.IO.Path.GetTempPath() + fileName; 
System.IO.File.WriteAllText(FilePath, sRes); 
FileStream MyFileStream = new FileStream(FilePath, FileMode.Open); 
long FileSize; 
FileSize = MyFileStream.Length; 
byte[] Buffer = new byte[(int)FileSize]; 
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length); 
MyFileStream.Close(); 
System.Web.HttpContext.Current.Response.AddHeader("content-type", "text/Calendar"); 
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); 
System.Web.HttpContext.Current.Response.BinaryWrite(Buffer); 
System.Web.HttpContext.Current.Response.Clear(); 
HttpContext.Current.Response.End(); 

在此先感謝...

回答

0
string fileName = "Test.ics"; 
InternetCalendaring.ICSBuilder icsbBuilder = new InternetCalendaring.ICSBuilder(vecVEvents); 
sRes = icsbBuilder.ICSBuildProcess(); 

byte[] Buffer = Encoding.Unicode.GetBytes(sRes); 

System.Web.HttpContext.Current.Response.AddHeader("content-type", "text/Calendar"); 
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); 
System.Web.HttpContext.Current.Response.BinaryWrite(Buffer); 
//System.Web.HttpContext.Current.Response.Clear(); 
HttpContext.Current.Response.End(); 
+0

哇。得到它..偉大的工作..感謝在噸 – user2877778 2014-10-08 12:20:02

+0

嗨,對不起,該文件中的數據不來...文件大小爲0字節.. :-( – user2877778 2014-10-08 12:49:06

+0

當然,我們不需要清除響應,然後發送給消費者 – Sohaty 2014-10-08 12:58:41

相關問題