我正在制定计划控制。我需要导出预约约会。 从下面的代码我已经在临时文件夹中创建了Test.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 :(得分: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();