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.