Kulingar
Kulingar

Reputation: 961

If I create a file in Codebehind where does the physical file acually exist?

    protected void Page_Load(object sender, EventArgs e)
    {
            System.IO.File.WriteAllText(@"C:\CallInformation.txt", "Some data");
    }

is CallInformation.txt on the Server? Or the client? If it's the server, other than specifying a computer name (@"\Workstation\c$\CallInformation.txt") how can I get it to save the file client side?

Upvotes: 1

Views: 360

Answers (4)

OnoSendai
OnoSendai

Reputation: 3970

The file would be create on the server. To write it locally, you would need a client framework other than just the W3C DOM compliant browser, such as Silverlight and (maybe) Flash - and even then the user would be prompted to allow it to happen.

Here's a post that explains how it can be done:

http://www.c-sharpcorner.com/uploadfile/dpatra/read-and-write-file-to-local-file-system-in-silverlight-4/

Hope it helps.

Upvotes: 1

humblelistener
humblelistener

Reputation: 1456

If you are writing a web application, you should understand that the code runs on the server. So the file is saved on the server.

To send it to the client, you have to write the contents of the file to the response stream.

Upvotes: 3

jfin3204
jfin3204

Reputation: 709

It is built on the server. It would be a major security vulnerability if you could create a file on a client without them physically accepting it. You could always send the data to them as a stream and allow them to choose where to save it.

Upvotes: 5

RQDQ
RQDQ

Reputation: 15579

It's on the server. The code behind executes in the context of the web server.

To get a file to download, there are a few ways. One way is to do something along these lines:

Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg");
Response.TransmitFile( Server.MapPath("~/images/sailbig.jpg") );
Response.End();

Upvotes: 4

Related Questions