hi. i am trying to create an aspx page where i can directly upload a file from the client to the server without user intervention. I would like to do something like when the user specifies the file path in the url, that particular file must be uploaded to the server.

example:
ht.tp://XXX.XXX.XXX.XXX/File_upload/File_Uploader.aspx?upload=C:/sample.csv&type=csv

The user can change the value after upload and what ever file he is specifying, it will be needed to be uploaded onto the server which is located at xxx.xxx.xxx.xxx

my sample code is:

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>File Uploader</title>
    <script runat="server" language="C#">
        private void Page_Load1(object sender, System.EventArgs e)
        {

            string file = Request.Params.Get("upload");
            string path = FilePathResolver.getPathForTEMP(); // this returns the path where the file will be uplaoded on the server.
            string fileName = @"temp.csv"; // this will be the file name. i am dealing only with csv files.
            string destFile = path + fileName;
            string type = Request.Params.Get("type");

            Response.AddHeader("Content-disposition", "attachment; filename=" + file);

            
            if (type.Equals("csv"))
                Response.ContentType = "text/csv";
            else if (type.Equals("txt"))
                Response.ContentType = "text/txt";
            else
                Response.ContentType = "application/octet-stream";

           //Response.WriteFile(destFile);
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("1"); // i am trying to append this value but the file is not being created at all.
            using (StreamWriter outfile = new StreamWriter(destFile))
            {
                outfile.Write(sb.ToString());
                outfile.Close();
            }

        }

this is just a trial to check if the csv file is being created on the server or not, and it is not being created.

i just want to copy the file on the client side to the server side and it has to be only by the aspx page in the format specified above.
if there is any other good way then please guide me. Thanks.

Recommended Answers

u wanna upload somethin at your server without using file
upload control...

i'm wondering why u r not using FileUpload Control
to transfer your files..

and you are uploading csv file, not a big deal....

why dnt you create a app on your machine for uploading files....

Jump to Post

All 8 Replies

hello dnanetwork, thank you for replying. I tried the file.copy option before posting this thread, this thing is working when both the files are on the same computer but not over the network(i could not make it work over the network at a path that i wanted, not server.mappath). i have figured out a totally different solution to my problem and it is not related to this file copying thing but i would really love to know how to transfer a file from a local computer(client) to the server. one method woulg be FTP but is there anything similar to the way i am trying to achieve it?

u wanna upload somethin at your server without using file
upload control...

i'm wondering why u r not using FileUpload Control
to transfer your files..

and you are uploading csv file, not a big deal....

why dnt you create a app on your machine for uploading files....
host it on your server...

it should work...

why FTP is coming in the picture..any bright reason to do that..?

why FTP is coming in the picture..any bright reason to do that..?

This particular file transfer that i am doing is just a small module of a bigger project that i am handling. all these things are back-end stuff. the user will be provided with a list to make his selection and according to his selection images will be generated. so to create these images i will need to use the csv file as the data file, call web services, return URLs and stuff, all these things need to be transparent to the user.

anyway i am figured out another back-door entrance to this project and it is working now the way i want it to be :)

cool... :)

can you share your solution with us.
I't will be very halpfull

thanks.

just wondering...have you found anything?

@meravsha and @kaizen007 ... unfortunately i cannot help you with this since i did not use this functionality in my project. I used a different approach to that project but I no longer have access to any of that code to provide you with. :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.