OK. I know it should be simple but I'm just beginning what is going to be a long hard road to writing a silverlight App that does things with Excel. So appologies now for any dumb questions (and future questions)
So, a simple question; what is the best way to load an excel file, and where should that file be placed? CODE NEEDED.
Many TIA
Steve
Here is a sample, including code, that shows reading an Excel file:
http://labs.infragistics.com/silverlight/lobsamples/2010.2/#/Samples/DocumentExport/ImportFromExcel
In your app you may want to give the end user the ability to open a file from their system. In that case instead of loading the file from the assembly as the sample above does, you would use the OpenFileDialog to prompt the end user for a file. When the user closes the dialog, it will give you access to a file stream that you can load using the Excel library.
Note that there are some security restrictions around how you launch the OpenFileDialog. It can only be done from a user initialted action, like a buttons click event, and you must show the dialog within something like .5 seconds of the user initiated event firing.
Hopefully that helps get you started. Let us know if you have any more questions.
Devin
Devin, hi and thanks.
I had already looked at the examples, as I had downloaded the samples browser and in the help documentation. For some reason I can't seem to load the data of even a simple file, when that file resides in the ClientBin folder.
The usage I'm looking for is relatively simple; use an excel file as a data source, however maintain that on the server as it will contain a variety of business rules and values that I don't want the user to have access to.
Although writing ASP.NET/WinForms apps for some time I'm coming to Silverlight RIA from extensive programming in Adobe Actionscript 3 (Flex programming); and what I am talking about was achieved using remoting in AS3, it was clunky and relied upon custom creation of c# dlls that lived on the server and web service calls from a Flash Client in the browser.... At least Silverlight is much nicer to work within from an integration of technologies point of view.
SO all I need is some code that will allow me to open xls on the server, read the file, and utilise the contents as business rules/model prior to binding to some presentation layer. I can't seem to get the file to open!
BTW is the IG Excel component async or sync in it's loading; I ask because if I were to load say and XML file, then I'd do this async with a callback on some loaded event.
Many thanks
Further to the last, I have had success based on the xls being compiled as an Embedded Resource; this is not the same as dynamically accessing it.
The reason for the loading requirement is to allow the owner of the xls to make changes and upload the file again. Effectively this would adhjust the business ruels/model.
Is there a way to load the file dynamically? A version flag would be contained in a cell as a comparitor for people uploading a changed file.
Attached is an example that demonstrates loading an Excel workbook from the ClientBin, which I beleive is what your looking to do. If not let me know.
You will have to add a reference to the Infragistics.Excel assembly in the Silverlight project toi get the sample working.
Devin Hi.
This is exactly the type of example that I'm looking for. It did throw an error message and didn't complete so did this compile and run on your system?
2 things:
1) The reference that I have for the Excel Assembly is InfragisticsSL4.Excel.v10.2 and noted yours as being v10.3; and
2) The example throws an error message:
System.Reflection.TargetInvocationException was unhandled by user code Message=An exception occurred during the operation, making the result invalid. Check InnerException for exception details. StackTrace: at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() at System.Net.OpenReadCompletedEventArgs.get_Result() at LoadReportExcelFile.Home.client_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e) at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e) at System.Net.WebClient.OpenReadOperationCompleted(Object arg) InnerException: System.Net.WebException Message=An exception occurred during a WebClient request. InnerException: System.NotSupportedException Message=The URI prefix is not recognized. StackTrace: at System.Net.WebRequest.Create(Uri requestUri) at System.Net.WebClient.GetWebRequest(Uri address) at System.Net.WebClient.OpenReadAsync(Uri address, Object userToken) InnerException: ....
Did you have this happen to you?
Is it an Assembly issue or something else?
Regards
Further to last for Devin and any others.
The .web project MUST be marked as the startup project.
This is so obscure that something as simple as this resolves the issue even when you click the 'go' button on the debugger and the project launches into a web browser.
Hope this helps anyone else wh has spent 5 hours trying to get a simple file in SilverLight to load from an external source asynchronously.
Devin further to the last, I have tried to refactor code down a bit to make it easier to debug, as in the following:
If you step through your code you will see that System.InvalidOperationException is being thrown on the wbURI objects properties.
Being a Silverlight newbie any ideas on resolving ?