473,836 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question refined - Copy file from client to server

CGW
I asked the question yesterday, but know better how to ask it, today:

I'm trying to use the File.Copy method to copy a file from a client to
server (.Net web app under IIS [IUSR account]). It looks to me that when I
give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C drive.
How do I pull from the client? Do I need a different class and/or method?
Filestream?
--
Thanks,

CGW
Feb 8 '06 #1
9 2420
When you are on the server, you cannot access the client's machine. The
server returns a bunch of HTML and script to the clientn (all text), the
client's browser then renders it all. All the server can ever do is send
that HTML and script in plain text, and then it's up to the client to render
the page.

Now, scripts will not have the necessary security rights to access files
directly on the client's machine - this would be a major security hole.

There are ActiveX controls, etc, you can write and have the client install,
but it involves the user installing it and giving it the rights it needs to
access the client machine.

I recommend you read up on how web servers work, how what they do interacts
with the client, etc.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:27******** *************** ***********@mic rosoft.com...
I asked the question yesterday, but know better how to ask it, today:

I'm trying to use the File.Copy method to copy a file from a client to
server (.Net web app under IIS [IUSR account]). It looks to me that when I
give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C
drive.
How do I pull from the client? Do I need a different class and/or method?
Filestream?
--
Thanks,

CGW

Feb 8 '06 #2
CGW
We already bring back files from the client to load into SQL using
filestreams and streamwriters. Maybe we both need to read up.
--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
When you are on the server, you cannot access the client's machine. The
server returns a bunch of HTML and script to the clientn (all text), the
client's browser then renders it all. All the server can ever do is send
that HTML and script in plain text, and then it's up to the client to render
the page.

Now, scripts will not have the necessary security rights to access files
directly on the client's machine - this would be a major security hole.

There are ActiveX controls, etc, you can write and have the client install,
but it involves the user installing it and giving it the rights it needs to
access the client machine.

I recommend you read up on how web servers work, how what they do interacts
with the client, etc.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:27******** *************** ***********@mic rosoft.com...
I asked the question yesterday, but know better how to ask it, today:

I'm trying to use the File.Copy method to copy a file from a client to
server (.Net web app under IIS [IUSR account]). It looks to me that when I
give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C
drive.
How do I pull from the client? Do I need a different class and/or method?
Filestream?
--
Thanks,

CGW


Feb 8 '06 #3
You are telling me that you have a web application that uses server side
code to get files sitting on the client computer of the person browing to
your .aspx page using the classes in the System.IO namespace?

In this case, I would love to see some sample code that can do this.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:9D******** *************** ***********@mic rosoft.com...
We already bring back files from the client to load into SQL using
filestreams and streamwriters. Maybe we both need to read up.
--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
When you are on the server, you cannot access the client's machine. The
server returns a bunch of HTML and script to the clientn (all text), the
client's browser then renders it all. All the server can ever do is send
that HTML and script in plain text, and then it's up to the client to
render
the page.

Now, scripts will not have the necessary security rights to access files
directly on the client's machine - this would be a major security hole.

There are ActiveX controls, etc, you can write and have the client
install,
but it involves the user installing it and giving it the rights it needs
to
access the client machine.

I recommend you read up on how web servers work, how what they do
interacts
with the client, etc.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:27******** *************** ***********@mic rosoft.com...
>I asked the question yesterday, but know better how to ask it, today:
>
> I'm trying to use the File.Copy method to copy a file from a client to
> server (.Net web app under IIS [IUSR account]). It looks to me that
> when I
> give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C
> drive.
> How do I pull from the client? Do I need a different class and/or
> method?
> Filestream?
> --
> Thanks,
>
> CGW


Feb 8 '06 #4
CGW
Here you go... here's one that uploads an Excel file using an input type of
file on the ASPX page:

DataSet ds = new DataSet();

HttpPostedFile file = flFile.PostedFi le;

// Make sure file is a valid Excel Spreadsheet
if (file.ContentTy pe != "applicatio n/vnd.ms-excel")
{
spMessages.Inne rHtml = "Please upload a valid Excel Spreadsheet!";
return;
}

int lastSlash = file.FileName.L astIndexOf("\\" );

DateTime dTime = DateTime.Now;

excelFileName = dTime.DayOfYear .ToString() + dTime.Hour.ToSt ring() +
dTime.Minute.To String() + dTime.Second.To String() +
dTime.Milliseco nd.ToString();

excelFileName += file.FileName.S ubstring((lastS lash + 1),
(file.FileName. Length - (lastSlash + 1)));
_excelUploadPat h += excelFileName;

csvFileName = excelFileName.R eplace("xls", "csv");
_csvUploadPath += csvFileName;

int fileLength = file.ContentLen gth;
byte[] fileData = new byte[fileLength];

// Read file contents into fileData byte[]
file.InputStrea m.Read(fileData , 0, fileLength);

// Upload Excel file
FileStream fs;
try
{
fs = new FileStream(_exc elUploadPath, FileMode.Create );
fs.Write(fileDa ta, 0, fileLength);
fs.Flush();
fs.Close();
}
catch (Exception err)
{
spMessages.Inne rHtml = "An error occurred attempting to upload
file!<br>" + err.ToString();
return;
}

// Create a datasource for the dataset
string sConnectionStri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=" + _excelUploadPat h + ";" +
"Extended Properties=Exce l 8.0;";

OleDbConnection objConn = new OleDbConnection (sConnectionStr ing);

try
{
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("S ELECT * FROM [" +
worksheetName + "]", objConn);
OleDbDataAdapte r objAdapter = new OleDbDataAdapte r();
objAdapter.Sele ctCommand = objCmdSelect;
objAdapter.Fill (ds);
}
catch (Exception e)
{
ErrorHelper.Han dleDBError("eve ntUpload.aspx.c s", "CreateCSV( )", e);
}
finally
{
if (objConn.State == ConnectionState .Open)
objConn.Close() ;

File.Delete(_ex celUploadPath);
}

--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
You are telling me that you have a web application that uses server side
code to get files sitting on the client computer of the person browing to
your .aspx page using the classes in the System.IO namespace?

In this case, I would love to see some sample code that can do this.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:9D******** *************** ***********@mic rosoft.com...
We already bring back files from the client to load into SQL using
filestreams and streamwriters. Maybe we both need to read up.
--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
When you are on the server, you cannot access the client's machine. The
server returns a bunch of HTML and script to the clientn (all text), the
client's browser then renders it all. All the server can ever do is send
that HTML and script in plain text, and then it's up to the client to
render
the page.

Now, scripts will not have the necessary security rights to access files
directly on the client's machine - this would be a major security hole.

There are ActiveX controls, etc, you can write and have the client
install,
but it involves the user installing it and giving it the rights it needs
to
access the client machine.

I recommend you read up on how web servers work, how what they do
interacts
with the client, etc.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:27******** *************** ***********@mic rosoft.com...
>I asked the question yesterday, but know better how to ask it, today:
>
> I'm trying to use the File.Copy method to copy a file from a client to
> server (.Net web app under IIS [IUSR account]). It looks to me that
> when I
> give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C
> drive.
> How do I pull from the client? Do I need a different class and/or
> method?
> Filestream?
> --
> Thanks,
>
> CGW


Feb 8 '06 #5
You are not using a FileStream to actually get the data from the client's
machine. You are not opening up the filestream directly to the client's
file.

The user is uploading the file, and you are getting the actual data because
the user browsed to the file so your page could upload it. The user
willingly opened the dialog, chose the file, then clicked a button to send
the file to the server. Then you are just taking that uploaded file, and
doing something with it on the server.

This is nothing like wanting to have server side code that just goes to a
given client file, and does something with it.

This brings me back to my original point of the server not being able to
just manipulate the files on a client machine at will.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:4D******** *************** ***********@mic rosoft.com...
Here you go... here's one that uploads an Excel file using an input type
of
file on the ASPX page:

DataSet ds = new DataSet();

HttpPostedFile file = flFile.PostedFi le;

// Make sure file is a valid Excel Spreadsheet
if (file.ContentTy pe != "applicatio n/vnd.ms-excel")
{
spMessages.Inne rHtml = "Please upload a valid Excel Spreadsheet!";
return;
}

int lastSlash = file.FileName.L astIndexOf("\\" );

DateTime dTime = DateTime.Now;

excelFileName = dTime.DayOfYear .ToString() + dTime.Hour.ToSt ring() +
dTime.Minute.To String() + dTime.Second.To String() +
dTime.Milliseco nd.ToString();

excelFileName += file.FileName.S ubstring((lastS lash + 1),
(file.FileName. Length - (lastSlash + 1)));
_excelUploadPat h += excelFileName;

csvFileName = excelFileName.R eplace("xls", "csv");
_csvUploadPath += csvFileName;

int fileLength = file.ContentLen gth;
byte[] fileData = new byte[fileLength];

// Read file contents into fileData byte[]
file.InputStrea m.Read(fileData , 0, fileLength);

// Upload Excel file
FileStream fs;
try
{
fs = new FileStream(_exc elUploadPath, FileMode.Create );
fs.Write(fileDa ta, 0, fileLength);
fs.Flush();
fs.Close();
}
catch (Exception err)
{
spMessages.Inne rHtml = "An error occurred attempting to upload
file!<br>" + err.ToString();
return;
}

// Create a datasource for the dataset
string sConnectionStri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=" + _excelUploadPat h + ";" +
"Extended Properties=Exce l 8.0;";

OleDbConnection objConn = new OleDbConnection (sConnectionStr ing);

try
{
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("S ELECT * FROM [" +
worksheetName + "]", objConn);
OleDbDataAdapte r objAdapter = new OleDbDataAdapte r();
objAdapter.Sele ctCommand = objCmdSelect;
objAdapter.Fill (ds);
}
catch (Exception e)
{
ErrorHelper.Han dleDBError("eve ntUpload.aspx.c s", "CreateCSV( )", e);
}
finally
{
if (objConn.State == ConnectionState .Open)
objConn.Close() ;

File.Delete(_ex celUploadPath);
}

--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
You are telling me that you have a web application that uses server side
code to get files sitting on the client computer of the person browing to
your .aspx page using the classes in the System.IO namespace?

In this case, I would love to see some sample code that can do this.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:9D******** *************** ***********@mic rosoft.com...
> We already bring back files from the client to load into SQL using
> filestreams and streamwriters. Maybe we both need to read up.
> --
> Thanks,
>
> CGW
>
>
> "Marina Levit [MVP]" wrote:
>
>> When you are on the server, you cannot access the client's machine.
>> The
>> server returns a bunch of HTML and script to the clientn (all text),
>> the
>> client's browser then renders it all. All the server can ever do is
>> send
>> that HTML and script in plain text, and then it's up to the client to
>> render
>> the page.
>>
>> Now, scripts will not have the necessary security rights to access
>> files
>> directly on the client's machine - this would be a major security
>> hole.
>>
>> There are ActiveX controls, etc, you can write and have the client
>> install,
>> but it involves the user installing it and giving it the rights it
>> needs
>> to
>> access the client machine.
>>
>> I recommend you read up on how web servers work, how what they do
>> interacts
>> with the client, etc.
>>
>> "CGW" <CG*@discussion s.microsoft.com > wrote in message
>> news:27******** *************** ***********@mic rosoft.com...
>> >I asked the question yesterday, but know better how to ask it, today:
>> >
>> > I'm trying to use the File.Copy method to copy a file from a client
>> > to
>> > server (.Net web app under IIS [IUSR account]). It looks to me that
>> > when I
>> > give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C
>> > drive.
>> > How do I pull from the client? Do I need a different class and/or
>> > method?
>> > Filestream?
>> > --
>> > Thanks,
>> >
>> > CGW
>>
>>
>>


Feb 8 '06 #6
CGW
Well then, please forgive me because I didn't state my question correctly...

The user will still choose the file. What I need to do is to copy that file
to a directory on the server, rather than load it into SQL. And THAT is my
question. How to do that best.
--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
You are not using a FileStream to actually get the data from the client's
machine. You are not opening up the filestream directly to the client's
file.

The user is uploading the file, and you are getting the actual data because
the user browsed to the file so your page could upload it. The user
willingly opened the dialog, chose the file, then clicked a button to send
the file to the server. Then you are just taking that uploaded file, and
doing something with it on the server.

This is nothing like wanting to have server side code that just goes to a
given client file, and does something with it.

This brings me back to my original point of the server not being able to
just manipulate the files on a client machine at will.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:4D******** *************** ***********@mic rosoft.com...
Here you go... here's one that uploads an Excel file using an input type
of
file on the ASPX page:

DataSet ds = new DataSet();

HttpPostedFile file = flFile.PostedFi le;

// Make sure file is a valid Excel Spreadsheet
if (file.ContentTy pe != "applicatio n/vnd.ms-excel")
{
spMessages.Inne rHtml = "Please upload a valid Excel Spreadsheet!";
return;
}

int lastSlash = file.FileName.L astIndexOf("\\" );

DateTime dTime = DateTime.Now;

excelFileName = dTime.DayOfYear .ToString() + dTime.Hour.ToSt ring() +
dTime.Minute.To String() + dTime.Second.To String() +
dTime.Milliseco nd.ToString();

excelFileName += file.FileName.S ubstring((lastS lash + 1),
(file.FileName. Length - (lastSlash + 1)));
_excelUploadPat h += excelFileName;

csvFileName = excelFileName.R eplace("xls", "csv");
_csvUploadPath += csvFileName;

int fileLength = file.ContentLen gth;
byte[] fileData = new byte[fileLength];

// Read file contents into fileData byte[]
file.InputStrea m.Read(fileData , 0, fileLength);

// Upload Excel file
FileStream fs;
try
{
fs = new FileStream(_exc elUploadPath, FileMode.Create );
fs.Write(fileDa ta, 0, fileLength);
fs.Flush();
fs.Close();
}
catch (Exception err)
{
spMessages.Inne rHtml = "An error occurred attempting to upload
file!<br>" + err.ToString();
return;
}

// Create a datasource for the dataset
string sConnectionStri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=" + _excelUploadPat h + ";" +
"Extended Properties=Exce l 8.0;";

OleDbConnection objConn = new OleDbConnection (sConnectionStr ing);

try
{
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("S ELECT * FROM [" +
worksheetName + "]", objConn);
OleDbDataAdapte r objAdapter = new OleDbDataAdapte r();
objAdapter.Sele ctCommand = objCmdSelect;
objAdapter.Fill (ds);
}
catch (Exception e)
{
ErrorHelper.Han dleDBError("eve ntUpload.aspx.c s", "CreateCSV( )", e);
}
finally
{
if (objConn.State == ConnectionState .Open)
objConn.Close() ;

File.Delete(_ex celUploadPath);
}

--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
You are telling me that you have a web application that uses server side
code to get files sitting on the client computer of the person browing to
your .aspx page using the classes in the System.IO namespace?

In this case, I would love to see some sample code that can do this.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:9D******** *************** ***********@mic rosoft.com...
> We already bring back files from the client to load into SQL using
> filestreams and streamwriters. Maybe we both need to read up.
> --
> Thanks,
>
> CGW
>
>
> "Marina Levit [MVP]" wrote:
>
>> When you are on the server, you cannot access the client's machine.
>> The
>> server returns a bunch of HTML and script to the clientn (all text),
>> the
>> client's browser then renders it all. All the server can ever do is
>> send
>> that HTML and script in plain text, and then it's up to the client to
>> render
>> the page.
>>
>> Now, scripts will not have the necessary security rights to access
>> files
>> directly on the client's machine - this would be a major security
>> hole.
>>
>> There are ActiveX controls, etc, you can write and have the client
>> install,
>> but it involves the user installing it and giving it the rights it
>> needs
>> to
>> access the client machine.
>>
>> I recommend you read up on how web servers work, how what they do
>> interacts
>> with the client, etc.
>>
>> "CGW" <CG*@discussion s.microsoft.com > wrote in message
>> news:27******** *************** ***********@mic rosoft.com...
>> >I asked the question yesterday, but know better how to ask it, today:
>> >
>> > I'm trying to use the File.Copy method to copy a file from a client
>> > to
>> > server (.Net web app under IIS [IUSR account]). It looks to me that
>> > when I
>> > give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C
>> > drive.
>> > How do I pull from the client? Do I need a different class and/or
>> > method?
>> > Filestream?
>> > --
>> > Thanks,
>> >
>> > CGW
>>
>>
>>


Feb 8 '06 #7
You can't copy the file, because you only have access to the file in its
uploaded form - which is the stream.

You already wrote code in that snippet you posted to read this stream and
write it out to disk. So it looks to me like you already have this written.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:81******** *************** ***********@mic rosoft.com...
Well then, please forgive me because I didn't state my question
correctly...

The user will still choose the file. What I need to do is to copy that
file
to a directory on the server, rather than load it into SQL. And THAT is my
question. How to do that best.
--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
You are not using a FileStream to actually get the data from the client's
machine. You are not opening up the filestream directly to the client's
file.

The user is uploading the file, and you are getting the actual data
because
the user browsed to the file so your page could upload it. The user
willingly opened the dialog, chose the file, then clicked a button to
send
the file to the server. Then you are just taking that uploaded file, and
doing something with it on the server.

This is nothing like wanting to have server side code that just goes to a
given client file, and does something with it.

This brings me back to my original point of the server not being able to
just manipulate the files on a client machine at will.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:4D******** *************** ***********@mic rosoft.com...
> Here you go... here's one that uploads an Excel file using an input
> type
> of
> file on the ASPX page:
>
> DataSet ds = new DataSet();
>
> HttpPostedFile file = flFile.PostedFi le;
>
> // Make sure file is a valid Excel Spreadsheet
> if (file.ContentTy pe != "applicatio n/vnd.ms-excel")
> {
> spMessages.Inne rHtml = "Please upload a valid Excel Spreadsheet!";
> return;
> }
>
> int lastSlash = file.FileName.L astIndexOf("\\" );
>
> DateTime dTime = DateTime.Now;
>
> excelFileName = dTime.DayOfYear .ToString() + dTime.Hour.ToSt ring() +
> dTime.Minute.To String() + dTime.Second.To String() +
> dTime.Milliseco nd.ToString();
>
> excelFileName += file.FileName.S ubstring((lastS lash + 1),
> (file.FileName. Length - (lastSlash + 1)));
> _excelUploadPat h += excelFileName;
>
> csvFileName = excelFileName.R eplace("xls", "csv");
> _csvUploadPath += csvFileName;
>
> int fileLength = file.ContentLen gth;
> byte[] fileData = new byte[fileLength];
>
> // Read file contents into fileData byte[]
> file.InputStrea m.Read(fileData , 0, fileLength);
>
> // Upload Excel file
> FileStream fs;
> try
> {
> fs = new FileStream(_exc elUploadPath, FileMode.Create );
> fs.Write(fileDa ta, 0, fileLength);
> fs.Flush();
> fs.Close();
> }
> catch (Exception err)
> {
> spMessages.Inne rHtml = "An error occurred attempting to upload
> file!<br>" + err.ToString();
> return;
> }
>
> // Create a datasource for the dataset
> string sConnectionStri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
> "Data Source=" + _excelUploadPat h + ";" +
> "Extended Properties=Exce l 8.0;";
>
> OleDbConnection objConn = new OleDbConnection (sConnectionStr ing);
>
> try
> {
> objConn.Open();
> OleDbCommand objCmdSelect = new OleDbCommand("S ELECT * FROM [" +
> worksheetName + "]", objConn);
> OleDbDataAdapte r objAdapter = new OleDbDataAdapte r();
> objAdapter.Sele ctCommand = objCmdSelect;
> objAdapter.Fill (ds);
> }
> catch (Exception e)
> {
> ErrorHelper.Han dleDBError("eve ntUpload.aspx.c s", "CreateCSV( )", e);
> }
> finally
> {
> if (objConn.State == ConnectionState .Open)
> objConn.Close() ;
>
> File.Delete(_ex celUploadPath);
> }
>
> --
> Thanks,
>
> CGW
>
>
> "Marina Levit [MVP]" wrote:
>
>> You are telling me that you have a web application that uses server
>> side
>> code to get files sitting on the client computer of the person browing
>> to
>> your .aspx page using the classes in the System.IO namespace?
>>
>> In this case, I would love to see some sample code that can do this.
>>
>> "CGW" <CG*@discussion s.microsoft.com > wrote in message
>> news:9D******** *************** ***********@mic rosoft.com...
>> > We already bring back files from the client to load into SQL using
>> > filestreams and streamwriters. Maybe we both need to read up.
>> > --
>> > Thanks,
>> >
>> > CGW
>> >
>> >
>> > "Marina Levit [MVP]" wrote:
>> >
>> >> When you are on the server, you cannot access the client's machine.
>> >> The
>> >> server returns a bunch of HTML and script to the clientn (all
>> >> text),
>> >> the
>> >> client's browser then renders it all. All the server can ever do
>> >> is
>> >> send
>> >> that HTML and script in plain text, and then it's up to the client
>> >> to
>> >> render
>> >> the page.
>> >>
>> >> Now, scripts will not have the necessary security rights to access
>> >> files
>> >> directly on the client's machine - this would be a major security
>> >> hole.
>> >>
>> >> There are ActiveX controls, etc, you can write and have the client
>> >> install,
>> >> but it involves the user installing it and giving it the rights it
>> >> needs
>> >> to
>> >> access the client machine.
>> >>
>> >> I recommend you read up on how web servers work, how what they do
>> >> interacts
>> >> with the client, etc.
>> >>
>> >> "CGW" <CG*@discussion s.microsoft.com > wrote in message
>> >> news:27******** *************** ***********@mic rosoft.com...
>> >> >I asked the question yesterday, but know better how to ask it,
>> >> >today:
>> >> >
>> >> > I'm trying to use the File.Copy method to copy a file from a
>> >> > client
>> >> > to
>> >> > server (.Net web app under IIS [IUSR account]). It looks to me
>> >> > that
>> >> > when I
>> >> > give a path like @"C:\holdfiles\ myfile.txt" it looks on the
>> >> > server C
>> >> > drive.
>> >> > How do I pull from the client? Do I need a different class and/or
>> >> > method?
>> >> > Filestream?
>> >> > --
>> >> > Thanks,
>> >> >
>> >> > CGW
>> >>
>> >>
>> >>
>>
>>
>>


Feb 8 '06 #8
CGW
I'll be damned! I missed it. Thanks!
--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
You can't copy the file, because you only have access to the file in its
uploaded form - which is the stream.

You already wrote code in that snippet you posted to read this stream and
write it out to disk. So it looks to me like you already have this written.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:81******** *************** ***********@mic rosoft.com...
Well then, please forgive me because I didn't state my question
correctly...

The user will still choose the file. What I need to do is to copy that
file
to a directory on the server, rather than load it into SQL. And THAT is my
question. How to do that best.
--
Thanks,

CGW
"Marina Levit [MVP]" wrote:
You are not using a FileStream to actually get the data from the client's
machine. You are not opening up the filestream directly to the client's
file.

The user is uploading the file, and you are getting the actual data
because
the user browsed to the file so your page could upload it. The user
willingly opened the dialog, chose the file, then clicked a button to
send
the file to the server. Then you are just taking that uploaded file, and
doing something with it on the server.

This is nothing like wanting to have server side code that just goes to a
given client file, and does something with it.

This brings me back to my original point of the server not being able to
just manipulate the files on a client machine at will.

"CGW" <CG*@discussion s.microsoft.com > wrote in message
news:4D******** *************** ***********@mic rosoft.com...
> Here you go... here's one that uploads an Excel file using an input
> type
> of
> file on the ASPX page:
>
> DataSet ds = new DataSet();
>
> HttpPostedFile file = flFile.PostedFi le;
>
> // Make sure file is a valid Excel Spreadsheet
> if (file.ContentTy pe != "applicatio n/vnd.ms-excel")
> {
> spMessages.Inne rHtml = "Please upload a valid Excel Spreadsheet!";
> return;
> }
>
> int lastSlash = file.FileName.L astIndexOf("\\" );
>
> DateTime dTime = DateTime.Now;
>
> excelFileName = dTime.DayOfYear .ToString() + dTime.Hour.ToSt ring() +
> dTime.Minute.To String() + dTime.Second.To String() +
> dTime.Milliseco nd.ToString();
>
> excelFileName += file.FileName.S ubstring((lastS lash + 1),
> (file.FileName. Length - (lastSlash + 1)));
> _excelUploadPat h += excelFileName;
>
> csvFileName = excelFileName.R eplace("xls", "csv");
> _csvUploadPath += csvFileName;
>
> int fileLength = file.ContentLen gth;
> byte[] fileData = new byte[fileLength];
>
> // Read file contents into fileData byte[]
> file.InputStrea m.Read(fileData , 0, fileLength);
>
> // Upload Excel file
> FileStream fs;
> try
> {
> fs = new FileStream(_exc elUploadPath, FileMode.Create );
> fs.Write(fileDa ta, 0, fileLength);
> fs.Flush();
> fs.Close();
> }
> catch (Exception err)
> {
> spMessages.Inne rHtml = "An error occurred attempting to upload
> file!<br>" + err.ToString();
> return;
> }
>
> // Create a datasource for the dataset
> string sConnectionStri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
> "Data Source=" + _excelUploadPat h + ";" +
> "Extended Properties=Exce l 8.0;";
>
> OleDbConnection objConn = new OleDbConnection (sConnectionStr ing);
>
> try
> {
> objConn.Open();
> OleDbCommand objCmdSelect = new OleDbCommand("S ELECT * FROM [" +
> worksheetName + "]", objConn);
> OleDbDataAdapte r objAdapter = new OleDbDataAdapte r();
> objAdapter.Sele ctCommand = objCmdSelect;
> objAdapter.Fill (ds);
> }
> catch (Exception e)
> {
> ErrorHelper.Han dleDBError("eve ntUpload.aspx.c s", "CreateCSV( )", e);
> }
> finally
> {
> if (objConn.State == ConnectionState .Open)
> objConn.Close() ;
>
> File.Delete(_ex celUploadPath);
> }
>
> --
> Thanks,
>
> CGW
>
>
> "Marina Levit [MVP]" wrote:
>
>> You are telling me that you have a web application that uses server
>> side
>> code to get files sitting on the client computer of the person browing
>> to
>> your .aspx page using the classes in the System.IO namespace?
>>
>> In this case, I would love to see some sample code that can do this.
>>
>> "CGW" <CG*@discussion s.microsoft.com > wrote in message
>> news:9D******** *************** ***********@mic rosoft.com...
>> > We already bring back files from the client to load into SQL using
>> > filestreams and streamwriters. Maybe we both need to read up.
>> > --
>> > Thanks,
>> >
>> > CGW
>> >
>> >
>> > "Marina Levit [MVP]" wrote:
>> >
>> >> When you are on the server, you cannot access the client's machine.
>> >> The
>> >> server returns a bunch of HTML and script to the clientn (all
>> >> text),
>> >> the
>> >> client's browser then renders it all. All the server can ever do
>> >> is
>> >> send
>> >> that HTML and script in plain text, and then it's up to the client
>> >> to
>> >> render
>> >> the page.
>> >>
>> >> Now, scripts will not have the necessary security rights to access
>> >> files
>> >> directly on the client's machine - this would be a major security
>> >> hole.
>> >>
>> >> There are ActiveX controls, etc, you can write and have the client
>> >> install,
>> >> but it involves the user installing it and giving it the rights it
>> >> needs
>> >> to
>> >> access the client machine.
>> >>
>> >> I recommend you read up on how web servers work, how what they do
>> >> interacts
>> >> with the client, etc.
>> >>
>> >> "CGW" <CG*@discussion s.microsoft.com > wrote in message
>> >> news:27******** *************** ***********@mic rosoft.com...
>> >> >I asked the question yesterday, but know better how to ask it,
>> >> >today:
>> >> >
>> >> > I'm trying to use the File.Copy method to copy a file from a
>> >> > client
>> >> > to
>> >> > server (.Net web app under IIS [IUSR account]). It looks to me
>> >> > that
>> >> > when I
>> >> > give a path like @"C:\holdfiles\ myfile.txt" it looks on the
>> >> > server C
>> >> > drive.
>> >> > How do I pull from the client? Do I need a different class and/or
>> >> > method?
>> >> > Filestream?
>> >> > --
>> >> > Thanks,
>> >> >
>> >> > CGW
>> >>
>> >>
>> >>
>>
>>
>>


Feb 8 '06 #9
CGW
Found it. It was simple. The "SaveAs" method was all I needed.
--
Thanks,

CGW
"CGW" wrote:
I asked the question yesterday, but know better how to ask it, today:

I'm trying to use the File.Copy method to copy a file from a client to
server (.Net web app under IIS [IUSR account]). It looks to me that when I
give a path like @"C:\holdfiles\ myfile.txt" it looks on the server C drive.
How do I pull from the client? Do I need a different class and/or method?
Filestream?
--
Thanks,

CGW

Feb 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1692
by: J Poirier | last post by:
Hi All, I'm hoping that someone might have some pointers or examples on how to proceed with a solution to the following problem: A test application, which produces a trace file, is being run for very long periods of time. Say 72 hours or more.
27
3083
by: Gene Ellis | last post by:
Something strange is happening, but I bet it is a quick fix. My favicon image is showing up in the URL bar, for a couple of seconds, but then it disappears and the default browser icon is displayed. When I reload the page, the same thing happens. The correct icon appears for a few seconds (while the page is loading), but then goes away. You can see that here: http://webdev.ucop.edu/tltc_ph2/index_icon.html
7
3375
by: CT | last post by:
Hi, This might seem like a basic question but I have some doubts, please humour me. I have a client-server application using java where each client on each machine needs to directly communicate directly with the database. Do I need a separate db2 connect on each such machine. Please advice.
12
9914
by: Corey Burnett | last post by:
I have a client that has a split database (front-end/back-end). They are also using Access security - MDW file. The front end MDE file, the back end MDB file, and the MDW file are all located on a shared folder on the file server. They have two populations of users - local and remote. *ALL* users currently get to the system via a Citrix login. They log in to Citrix and get a Citrix desktop. Then they start the application via a...
1
3902
by: POnfri | last post by:
Hi, I have a problem in a peace of code were i'm doing a file copy using File.Copy. The Source is local and the target is a remote machine. Example: File.Copy(C:\temp\hi.txt, \\myremote\c$\temp\hi.txt, true); This API is run from a web service that exposes it. The problem is as follows: 1) I request a page (On the web service machine) from my web server (Note
3
1293
by: Ray | last post by:
Dear all, Now, I have 3 projects of class library and 1 project of window application. The window application will call the 3 class librarys. So should I make 4 .snk files for each project? Or one .snk file linked by Assemblyinfo.vb of each class library? The main target of me is that I can install the window application once in the client PC, then the client PC can update its version after I compile in the program in the server. Please...
4
2176
by: Peter | last post by:
I have a button on my ASP.NET 2.0 web page labelled "Copy to Clipboard" which must use server side code to format some data in a specific manner and then copy it to the client clipboard so it can be pasted into another application. Initially I planned to have the server-side code put the data string into a cookie and then use a client-side Javascript function referenced in the button's OnClientClick attribute to copy the contents of the...
3
1184
by: CeJay | last post by:
Hi All Ok this is a bit of a doozy for me. Work related question, I have been tasked with sorting out this issue at work, but don't really have much background in this field, but theres no one else in my team that can do it. Bit of a background on the problem. At work we have a server and a client machine, They are both running on Windows Server 2000. They both have on them proprietry software for the client which uses MSSQL. Late last...
5
5899
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to store a DataTable in any other way outside of our servers. In doing so, we leave ourselves open to large memory requirements. Furthermore, most web pages do not really support multiple changes per transaction. In other words, when the user submits...
0
9677
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10560
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10607
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10262
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6986
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5838
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.