简体   繁体   中英

How to create and save ics file using save dialog box?

I am working on the schedule control. i need to export the schedule appointments. from the below code i have created the Test.ics file in temp folder and then copied to new location.

how to do save the file without save temporarily in the temp folder. Is it possible to store the file in buffer or any temp object instead of storing it in the temp folder?

please find my code snippet below...

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();

Thanks in advance...

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM