[ B_E_N_K_O_ @ 21.04.2008. 10:52 ] @
Imam problem. Trebam da prikazem izvestaje u Excel-u. Do sada su izvestaji bili u pdf-u i sve je bilo ok. Sada korisnice hoce da im se izvestaji otvaraju u Excelu. U pitanju je ASP.NET aplikacija i SQl Server 2005. Na racunaru je instaliran office 2007. Kada se kod izvrsi korisnici dobijaju poruku "Do you want to open or save this file" i dobijaju opcije open, save i cancel. Nakon klika na open dolazi do vrlo cudnog upozorenja "The file you are trying to open, [naziv asp.net strane], is in a different format then specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now". Nakon klika na yes sve je uredu file se otvara u excel-u. Problem je u tome sto je naziv file-a ustvari naziv asp.net strane. Evo koda: Code: public partial class frmIzvestaj: Page { public ReportingService rs = new ReportingService(); public SessionHeader sh = new SessionHeader(); private void Page_PreInit(object sender, EventArgs e) { rs.Credentials = System.Net.CredentialCache.DefaultCredentials; string encoding; string mimeType; ParameterValue[ pars = new ParameterValue[0]; ParameterValue[ parametersUsed; Warning[ warning; string[ streemIDS; byte[ data; string reportPath = "putanja do izvestaja"; string devInfo = "<DeviceInfo>"+ "<Toolbar>False</Toolbar>"+ "<HTMLFragment>False</HTMLFragment>"+ " </DeviceInfo>"; data = rs.Render(reportPath,"EXCEL",null,devInfo,pars,null,null,out encoding, out mimeType,out parametersUsed,out warning,out streemIDS); this.sh.SessionId = rs.SessionHeaderValue.SessionId; string root = "~/Media/"; string FileName = root + "Izvestaj" + this.Session.SessionID.ToString() + ".xls"; string AbsoluteFileName = MapPath(FileName); base.Response.ClearContent(); base.Response.ClearHeaders(); base.Response.ContentType = "application/vnd.ms-excel"; base.Response.AddHeader("content-disposition", "attachment; filename=" + FileName); base.Response.BinaryWrite(data); base.Response.Flush(); base.Response.Close(); } |