I am using FileUpload control of asp.net and uploading the excel with some data. I can't save it in some folder. I can have stream of excel sheet file or I can have Blobstream after uploading excel as a blob. Now I want to convert that excel sheets 1st sheet to datatable so how shall I do that? I am using C# .NET. I don't want to use Interop library. I can use external libraries. Oledb connection is getting failed since I don't have any physical path of excel as a data source. I tried following links:
1) http://www.codeproject.com/Articles/14639/Fast-Excel-file-reader-with-basic-functionality
2) http://exceldatareader.codeplex.com/
Please help.
Depending on the type of Excel file you can use the examples you posted or go for the OpenXML alternative (for xlsx files): http://openexcel.codeplex.com/
Now, the problem with the physical path is easy to solve. Saving the file to blob storage is great. But if you want, you can also save it in a local resource to have it locally. This will allow you to process the file using a simple OleDb connection. Once you're done with the file, you can just delete it from the local resource (it will still be available in the blob storage since you also uploaded it there).
Don't forget to have some kind of clean up mechanism in case your processing fails. You wouldn't want to end up with a disk filled with temporary files (even though it could take a while before this happens).
Read more on local resources here: http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx
You should use OpenXML SDK which is an officially suggested way of working with MS Office documents - http://www.microsoft.com/download/en/details.aspx?id=5124
I first created local storage as per the link:
http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx
suggested by Sandrino above. Thanks Sandrino for this. Then I used oledb connection and it gave me an error "Microsoft.Jet.Oledb.4.0 dll is not registered". Then I logged on to the azure server and in the IIS changed app pool configuration for 32-bit. To change app pool to 32-bit refer the following link:
http://blog.nkadesign.com/2008/windows-2008-the-microsoftjetoledb40-provider-is-not-registered-on-the-local-machine/
The approach you followed is not the correct one, as you said you logged on to azure and changed, the VM which is running on azure is not the permanent one for you. For any updates you are going to get new VM machine. you might have to find turn around for this, instead of modifying manually. You can make use of the startup tasks in your azure app. See the link below it may help you.
http://msdn.microsoft.com/en-us/library/gg456327.aspx
Related
This Question might be repeated, But I couldn't get solution regarding my problem so far. I'm new to Interop. I'm using excel file (as a database).
Here is data presentation in excel file
in my data If Card ID repeated then I need to increment '1' in Counter in the same row, similarly I need to fetch IP address of same row..
I'm using Interop Excel approach to insert data in excel file..
Kindly tell me how can I perform that update operation to that excel file through C# (WPF)
Sorry for bad English..
Thanks
I recommend using Closed XML
You write to the file directly and don't need Excel. It will need to be the latest version of an Excel file to work (The open xml standard).
Epplus.dll or npoi.dll will also read/write to excel files w/o excel.
Save the data in an XML or JSON file, then when you want to visualize them you create the excel file from these data, so you will have a very light file and easy to read and update if you wish.
I haven't done this specifically through wpf, but you can access powershell cmdlets through .net and powershell has commands for retrieving and writing Excel data.
That said, my experience has been it's very tedious and inconsistent with bugs. I would tell your client that using an Excel file as a database is impossible and certainly prone to failure in practice.
For one thing you will run into read/write restrictions if it is used by anything else.
If you don't mind to use comercial libraries, you can try to use Aspose.Cells. It has rich cells API and able to work without Excel interop API.
I have a workbook with a couple of external links.
Regularly we need to update the links to point to a new excel database, so I'm making a small windows application to do it automatically.
I'm trying to use OpenXML to get this done. I dont want to use Interop, coz it takes too long to open the file, change the link and then close the workbooks again.
Any Ideas , please let me know. I'm open to using ClosedXML to this as well.
Are you using this on a limited amount of machines? e.g. One laptop for the db admin? If yes I would suggest you use DSN connections in Excel and that you update them from the DSN editor when the db change
See the following in Windows.
C:\Windows\System32\odbcad32.exe
This way any files using these DSN will have updated connections.
I have ASP.NET web service, which is creating file in XML table format.
I need to convert this file into Excel 2003 format.
What can I use instead of Microsoft.Interop library?
UPDATE: I also need to copy format from the original file.
you can read the data from xml using linq and then insert it on the run using linq to excel with the dll provided in the post above.
also take a look at this article i hope it helps
http://blogs.msdn.com/b/bethmassi/archive/2007/10/30/quickly-import-and-export-excel-data-with-linq-to-xml.aspx
Have you tried OpenXML? Here is an example
With Office 2007
Look here for Cell Formatting
I use ExcelLibrary
I think it's a very easy to use tool.
you can transform an XML string to an excel file in one method.
I also heared about NPOI, maybe give it a look also.
I've found the answer by myself.
I could not use different libraries, because I had to open file in XML Table format and resave it to Excel 2003 format.
Maybe my experience in this question will help someone. I used Windows Server 2008 with IIS 7.0 and Excel Library Microsoft.Office.Interop.Excel version 12.
Microsoft says, that using Interop DLL may cause unpredictable result, but it's NOT impossible.
The main problem of using Interop classes lies into access to launch DCOM applications by user, that starts web-service.
To make web-service works correct in my way I did next:
I opened "dcomcnfg" and disable authorization for all DCOM
components.
Another way is to find exactly your DCOM objects and give
permissions to local launch to the user, that starts the service.
Gave permissions to registry branch
HKEY_CLASSES_ROOT\CLSID\ID_OF_MICROSOFT_APPLICATION_CLASS
ID_OF_MICROSOFT_APPLICATION_CLASS = class, which contained in
web-server error while accessing to Interop DLL
It's very strange, but important: I created folder
for 86x: C:\Windows\System32\config\systemprofile\Desktop
for 64x: C:\Windows\SysWOW64\config\systemprofile\Desktop
Gave write permission to web-service user to all folders, which my
web-service use, including folder from item (3).
If your web-service works under NETWORK SERVICE try to change it to some local user, maybe it may help you.
I'm on charge of building an ASP.NET MVC Document Management System. It have to be able to do basic document management tasks like adding, editing and searching entries and also perform versioning.
Anyways, I'm targeting PDF, Office and many image formats as the file attached to each document entry in the database. My question is: What design guidelines do pros follow when building the storage mechanism? Do they store the document files in the file system? Database? How file uploading is handled?
I used to upload the files to a temporal location while the user was editing the data and move it to permanent storage when the user confirmed the entry creation. Is this good? Any suggestions on improvement?
Files should generally be stored on a filesystem, rather than a database.
You will, however, have to consider some other things:
Are you planning on ever supporting load-balancing, replication, etc for your system?
If so, you'll need to support saving / loading files from a network location of some sort.
This can be trickier than you may imagine.
Are you planning to secure access to the files?
If so, you'll need to ensure they can't be read by someone who happens to know the URL.
eg: by returning the file as an attachment to a request.
This also prevents user-provided files being executed on your server - eg someone uploading an .aspx or .exe file and then accessing it.
I've got a pretty simple web form which lets users pick reports, one specific report they want in xls with pretty formatting instead of CSV. I've whipped up the report using COM INTEROP with excel 2007. It works on my local machine and can write the file, but on the web server it fails with this error:
Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.
There is plenty of disk space on the server, so I don't think it's that - could this be a permissions issue? I've escalated ASPNET and NETWORK SERVICE accounts to have write and modify access to the folder we're saving reports to - but still no joy. Any ideas?
Do I need to invoke the com object with a specific user account, or maybe elevate the interop calls to administrator account? Any idea how to do this?
Sorry guys, sorted it.
Serge you are halfway there. I ended up running Excel as administrator:
in component services, select excel application and choose admin as the user that runs it. Seems to work okay for the week of use it'll get :)
Thanks all!
SpreadsheetGear for .NET will let you save xls and xlsx workbooks directly to a response stream with IWorkbook.SaveToStream. It is all safe managed C# code so there is no need to run anything as admin and you will not run into the problems that Excel COM Interop bring on an ASP.NET server.
You can see some simple ASP.NET Excel Reporting samples (C# and VB) using SpreadsheetGear here and download the free trial here.
Disclaimer: I own SpreadsheetGear LLC
you might want to use impersonation for your ASPNET process; here's some info and example on how to do this: killing a win process from a C# console application: How do I set permissions? more info on impersonation How to implement impersonation in an ASP.NET application