via translate.google.com:
>>
When exporting to excel kompanet always creates a temporary file vnezavisimosti from what is specified in the call to not create the file. This file is created in the temporary directory, and if the user from running code under which the export eksel no human error occurs.
This error when using export poyavlyaets grid in sharepoint. And inside you have a check on the possibility of creating a file - it runs but you do not have permission to write and there is exception.
>>
Hello Gennady,
Thank you for your report. I have translated your description into English because there is a chance that our customers might find our conversation.
I have discussed this issue with our team:
I am afraid we do not understand the following statement: And inside you have a check on the possibility of creating a file.
We do not create temporary files in our code. All temporary information is stored in the server's memory.
Maybe, you need to use the ASPxGridViewExporter.WriteXls method to export the grid into MemoryStream. After that, you will be able to send a file to the server response as in the ASPxGridViewExporter.WriteXlsToResponse method).
Thanks.
Vest
You write
"I am afraid we do not understand the following statement: And inside you have a check on the possibility of creating a file.
We do not create temporary files in our code. All temporary information is stored in the server's memory."
namespace DevExpress.XtraExport {
public class XlsxPackage {
#region inner classes
class StreamProviderCreator {
bool? canUseFileStream;
bool CanUseFileStream {
get {
if(!canUseFileStream.HasValue) {
try {
using(FileStreamProvider provider = new FileStreamProvider()) {
System.Diagnostics.Debug.Assert(provider.Stream != null);
}
canUseFileStream = true;
} catch(System.Security.SecurityException) {
canUseFileStream = false;
}
}
return canUseFileStream.Value;
}
}
public StreamProvider Create() {
return CanUseFileStream ? new FileStreamProvider() : new StreamProvider();
}
}
.....
class FileStreamProvider : StreamProvider {
string path = string.Empty;
protected override Stream CreateStream() {
path = Path.GetTempFileName();
return File.Create(path);
}
public override void Dispose() {
base.Dispose();
if(!string.IsNullOrEmpty(path)) {
File.Delete(path);
path = string.Empty;
}
}
}
Server Error in '/' Application.
--------------------------------------------------------------------------------
The directory name is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The directory name is invalid.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[IOException: The directory name is invalid.
]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10547621
System.IO.Path.GetTempFileName() +169
DevExpress.XtraExport.FileStreamProvider.CreateStream() +14
DevExpress.XtraExport.FileStreamProvider..ctor() +45
DevExpress.XtraExport.StreamProviderCreator.get_CanUseFileStream() +56
DevExpress.XtraExport.StreamProviderCreator.Create() +10
DevExpress.XtraExport.XlsxPackage.AddToArchive(ZipArchive archive, String path, XmlNode node) +41
DevExpress.XtraExport.XlsxPackage.CreateXlsxFile() +149
DevExpress.XtraExport.ExportXlsxProvider.DevExpress.XtraExport.IExportProvider.Commit() +556
DevExpress.XtraPrinting.Export.XLS.XlsExportProviderBase.CreateDocument(LayoutControlCollection layoutControls, Boolean correctImportBrickBounds) +98
DevExpress.XtraPrinting.PrintingSystemBase.ExportToXlsx(Stream stream, XlsxExportOptions options) +41
DevExpress.Web.ASPxGridView.Export.ASPxGridViewExporter.WriteXlsxCore(Stream stream, ExportOptionsBase exportOptions) +114
DevExpress.Web.ASPxGridView.Export.ASPxGridViewExporter.WriteToResponse(String fileName, Boolean saveAsFile, String fileFormat, ExportToStream getStream, ExportOptionsBase options) +82
DevExpress.Web.ASPxGridView.Export.ASPxGridViewExporter.WriteXlsxToResponse() +131
GTSMECoreBranding.ControlTemplates.GTSMEReportControls.OverdueRW.ASPxButtonExcel_Click(Object sender, EventArgs e) +127
DevExpress.Web.ASPxEditors.ASPxButton.OnClick(EventArgs e) +99
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
Let me explain again. There is no need to reproduce this bug in SharePoint environment. Code review shows that there is NO WriteXlsxToResponse() overload with option to choose type of underlying stream to use. Method have nondeterministic behavior, type of underlying stream depends on undocumented OS settings.
Look at bug call stack:
[14] System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10547621
[13] System.IO.Path.GetTempFileName() +169
[12] DevExpress.XtraExport.FileStreamProvider.CreateStream() +14
[11] DevExpress.XtraExport.FileStreamProvider..ctor() +45
[10] DevExpress.XtraExport.StreamProviderCreator.get_CanUseFileStream() +56
[9] DevExpress.XtraExport.StreamProviderCreator.Create() +10
[8] DevExpress.XtraExport.XlsxPackage.AddToArchive(ZipArchive archive, String path, XmlNode node) +41
[7] DevExpress.XtraExport.XlsxPackage.CreateXlsxFile() +149
[6] DevExpress.XtraExport.ExportXlsxProvider.DevExpress.XtraExport.IExportProvider.Commit() +556
[5] DevExpress.XtraPrinting.Export.XLS.XlsExportProviderBase.CreateDocument(LayoutControlCollection layoutControls, Boolean correctImportBrickBounds) +98
[4] DevExpress.XtraPrinting.PrintingSystemBase.ExportToXlsx(Stream stream, XlsxExportOptions options) +41
[3] DevExpress.Web.ASPxGridView.Export.ASPxGridViewExporter.WriteXlsxCore(Stream stream, ExportOptionsBase exportOptions) +114
[2] DevExpress.Web.ASPxGridView.Export.ASPxGridViewExporter.WriteToResponse(String fileName, Boolean saveAsFile, String fileFormat, ExportToStream getStream, ExportOptionsBase options) +82
[1] DevExpress.Web.ASPxGridView.Export.ASPxGridViewExporter.WriteXlsxToResponse() +131
Look at line [9]: DevExpress.XtraExport.StreamProviderCreator.Create() - this is the place where code hiddenly decide to use FileStream instead of MemoryStream.
Snippet from ..\DevExpress 2011.1\Components\Sources\DevExpress.XtraPrinting\DevExpress.Printing.Core\Export\ExportToExcel2007\XslxDom\XlsxPackage.cs:
public StreamProvider Create() {
return CanUseFileStream ? new FileStreamProvider() : new StreamProvider();
}
Look at line [10]: DevExpress.XtraExport.StreamProviderCreator.CanUseFileStream - this property returns true, if DevExpress.XtraExport.FileStreamProvider constructor does not raise SecurityException.
Snippet from ..\DevExpress 2011.1\Components\Sources\DevExpress.XtraPrinting\DevExpress.Printing.Core\Export\ExportToExcel2007\XslxDom\XlsxPackage.cs
bool CanUseFileStream {
get {
if(!canUseFileStream.HasValue) {
try {
using(FileStreamProvider provider = new FileStreamProvider()) {
System.Diagnostics.Debug.Assert(provider.Stream != null);
}
canUseFileStream = true;
} catch(System.Security.SecurityException) {
canUseFileStream = false;
}
}
return canUseFileStream.Value;
}
}
Look at line [12]: DevExpress.XtraExport.FileStreamProvider.CreateStream() - this method returns System.IO.FileStream as result of File.Create call.
Snippet from ..\DevExpress 2011.1\Components\Sources\DevExpress.XtraPrinting\DevExpress.Printing.Core\Export\ExportToExcel2007\XslxDom\XlsxPackage.cs
protected override Stream CreateStream() {
path = Path.GetTempFileName();
return File.Create(path);
}
As shown, behavior is nondeterministic. In case of SecurityException at line [10], DevExpress.XtraExport.StreamProvider have to be instantiated instead of DevExpress.XtraExport.FileStreamProvider. In that case line [12] call DevExpress.XtraExport.StreamProvider.CreateStream() - this method returns System.IO.MemoryStream.
Snippet from ..\DevExpress 2011.1\Components\Sources\DevExpress.XtraPrinting\DevExpress.Printing.Core\Export\ExportToExcel2007\XslxDom\XlsxPackage.cs
protected virtual Stream CreateStream() {
return new MemoryStream();
}
I think it is real bug. Behavior has to be deterministic: type of stream has to be parameterized (or use MemoryStream by default), also security requirements for FileStream have to be well-documented.
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.