views:

399

answers:

3

if i have this code, this creates a problems if other user that dont have acces to the network share tryes to run the method. How can i make this method write the file to the current users desktop?

        private void skriveTilFil()
        {
            StreamWriter writer = new StreamWriter(@"\\192.168.1.2\tmp\script.vbs");
            writer.WriteLine(scripttbx.Text);

            writer.Dispose();
        }
+3  A: 

On client/server web environments, you shouldn't be able to write data directly on client machines.

Can you download some data to your browser and/or run an ActiveXObject installed on client workstation? This can lead to some issues installing components on users machines, but will be more easily developed.

Rubens Farias
A: 

You can do it in an intranet environment by altering permissions/policies. You have to give the appropriate permissions to your ASP.NET application through IIS/Active Directory to the shares.

rick schott
This opens a big security hole - anyone that manages to take control of your server (I know, I know - that'll NEVER happen) can then write to any machines to which you've given ASP.NET write permissions.
David Lively
I am talking about a controlled intranet corporate environment, there are many many ways to make this happen without a security hole.
rick schott
thanks for the info, i will look in to this.
Darkmage
A: 

Browser security prevents this without using a control such as an ActiveX.

Any particular reason you don't just provide a download link?

David Lively
yeah, the script is generated from the values based on the content of 10 textboxes, so it is not yet there to be downloaded when the button is pushed, guess i have to rethink this one and approache it diffrently
Darkmage
Submit a form when the button is pushed. Have the action page for the form generate the file based on your form input, and return the generated file in place of another web page. You can do it entirely in memory without having to create anything on disk on the server. It's common to use a similar technique to retrieve binary files (images, etc) from a database.
David Lively