Silverlight 2.0 - Saving to a text file - silverlight

I'd like to save some simple text data to a file from my Silverlight app - to a CSV file.
The user presses on a button, the code generates the contents of the file in memory (a string), then a prompt appears asking to either open the file or Save to disk, like through a normal web page.
I found a complicated way to do it:
http://pagebrooks.com/archive/2008/07/16/save-file-dialog-in-silverlight.aspx
But wondered if there was a simpler way? Especially with the recent release of Silverlight 2.0.
Thanks.

Right now Silverlight 2 doesn't support saving directly to the user's disk even with a prompt. It is a feature being considered for future versions, but the work around of having the server push out the data is the current solution.

Just to update this thread -- Silverlight 3 has this capability now.

I do this right now with Silverlight 2.0, but the key is that the files are saved on the web server that hosts the Silverlight apps, by having the Silverlight app call web services.
Probably not what you are looking for, but this is an option.
Silverlight app calls web service, that posts the string
Web service saves the string as a file on the server
File is available through web app, or other means

Related

Chrome and file system objects

I have been doing a lot of research and trying to find a work around for a problem I have.
I am working with old code. Classic ASP with VBscript.
The tool we have working is file system objects. A user uploads a file into the input and it then gets added to the companies fileshare file. The problem is that google chrome has decided to not support VBscript. I easily converted the VBscript to Javascript using activeX but that is basically IE. We got it working in chrome using the plugin IE tabs. But we do not want to use the plug in.
My question is, since javascript is read only and we are running classic asp as our server side language is there any way that we can implement a cross browser file upload?
Converting ActiveX vbscript to javascript to run in crhome will not work. The reason for this is browsers have a security sandbox which prevents access to the filesystem. If the file share is on the same server as the web server, you would have to process the file uploads server side through a backend language like asp, asp.net, php.

Upload a large File to Sharepoint in a Silverlight application

I have tried what seems like about a dozen different methods of uploading files to sharepoint from a silverlight application. They either have severe limitations (file size limits of less than a meg or so) or lots of security issues that I have not been able to over come. I have tried:
WCF (We are trying not to use any custom WCF services at all FYI though this is the method that I have gotten to semi work)
Sharepoint Web services
Client object model
HTTP put
Webclient write stream
I have seen lots of different examples out there of people doing completely different things but none seem to work and all seem like they are the "old" way of doing things. I am using silverlight 4, sharepoint 2010 on IIS 7. Is there a best practice for uploading large (say 20-30 meg) files? I just want to dump a file into a document library.
I had similar issue. Tweaking web application level setting from central admin, changing asp.net limit in web.confit and following article helped me.
http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx
Just had a thought silverlight has a thing called an HTML Bridge which allows it to interact with the rest of the page. Consider calling a javascript function from Silverlight, and let the javascript function do the actual upload
UPDATE - the Javascript ClientOM doesn't seem to have the SaveBinaryDirect method :-(
How about doing some ExecuteQueryAsync and then in the success call back function (no longer on the UI thread), using the Microsoft.SharePoint.Client version of File? I know this would require downloading the larger assembly, so perhaps that's not so good.
I wonder if there is a way to get the clientOM use a more efficient binding when calling the web services...
Martin
The default upload size limit for the SharePoint client object model is 2 MB. You can change that limit by modifying the MaxReceivedMessageSize property of the service.
This can be done in two ways:
programatically - as described in this link - tho this won't work in Silverlight for example
trough the powershell. On the server where you have SharePoint installed, fire up the SharePoint Management Shell (make sure you run it under the farm administrator account) and run the following commands.
$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 52428800
$ws.Update()
This will change the upload limit to 52428800 bytes - or 50 MB. Now, restart the website hosting your SharePoint site (or the entire IIS) for the changes to take effect.

Silverlight security on the downloaded xap file

I want to develop a online trading application using silverlight in which I want to perform all the calculations at the client side instead of server.
First, Is it possible to run the whole application on the client side??
Second, How secure is silverlight xap file to prevent decoding the logic??
Please let me know.
Thanks,
Mahesh
You can use Silverlight Out-of-Browser which will increase your access to the local system if that is needed however is is still sandboxed and you do not get full access to system resources. If that is not a concern then you can perform your logic internal to the Silverlight application which remains in the browser and is indeed client side.
In terms of security to your .XAP file is nothing more then a re-branded .ZIP file. If someone can download your .XAP they can then get access to the .DLL's within the .XAP. Obfuscating the DLL's may hinder individuals from getting access to your code see this, however if intellectual property is something on the top of your list, I'd recommend not performing that logic client side as the other post mentions as well.

Silverlight OOTB Support for 'Save File' browser dialog

I am in the design stage of an application that must be both a standalone app & a web application (To save the costs of building 2 near identical applications twice). Basically I have opted to go for a silverlight OOTB application that will be installed on the standalone machines and they will write to a collection of files in the sandbox and occasionally talk to the server version. The same application (with a little configuration) will also operate on the webserver and store its data in a database.
I am however more of a WPF developer so I would like to cover some concerns I have before I go too far down this path...these are:
I hear you can pass a file out for the user to 'Save As' in their browser when using SL normally. Is there similar functionality with OOTB? Because I want to be able to save some of the local files to locations other than the sandbox (With user permission)?
Is is possible to configure OOTB to allow access to the filesystem outside of the sandbox?
Is there a way to programatically determine whether a silverlight application is running in OOTB mode (So I know what mode the application should be running in)?
Are there any major flaws in my ideas so far that would prevent this from being a possibility?
Silverlight 4 will provide support for out of browser trusted applications, which have more privileges that a normal sandboxed application but still not as much as a regular desktop application. Regarding file access, a trusted application will be able to access to some predefined folders such as MyDocuments, MyMusic, MyPictures, MyVideos, but not the entire filesystem. See here for details: http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-trusted-applications.aspx
As for how to know whether you are running out of browser or not, use Application.Current.RunningOffline.
Finally, I recommend you to take a look at PRISM. Among other things, it eases the task of sharing code between WPF and Silverlight, so you could consider developing a dual SL+WPF application.

Do I need a local web service to connect to database for Silverlight OOB?

I've done some cursory reading on Silverlight and data access. From what I can tell, I'll need a web service to hook up a Silverlight application to a database while it's running in browser. Is this true when it goes OOB? Or is there another method that should be used then?
Some background:
We have a .Net 2.0 Winforms application. We're trying to convert the functionality to a web app of some sort without rewriting the business logic. Our internal web developers all write in ColdFusion, so Adobe Air seemed to be a natural fit. However, we've found out that the only way to consume a .Net dll in Air is to write an EXE that makes function calls. (Perhaps something like a WCF service on the local machine.) Since that's the case, I thought I'd see how the data access was in Silverlight OOB, because we will have customers with limited-to-no internet connectivity and will need to be able to access an offline DB.
As far as I know, whether it runs in or out of browser it will need a web service or other means to hit a database. You cannot do it through the Silverlight application because of the sandbox security model used.
In 4.0 there is the added use of COM so you may be able to use that to your advantage.
Otherwise you would just be using a file stored in IsolatedStorage to persist data to, like an XML file for example. Maybe this is what you are looking for though?

Resources