Reading file from Client instead of Server

G

Guest

Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net so
if you have some sample code I can look at that would be great.

Thanks,
 
J

Jeff

I dont think this is possible. The only processing that can be done on
the client is through Javascript and Javascript cannot read from files.

Why are you trying to accomplish all of this on the client?

Jeff
 
E

Eliyahu Goldin

You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.
 
G

Guest

Because I want to allow the user to make edits to the data if they have to
before I save the data to a SQL Server DB.
 
G

Guest

Currently I have a System.Web.UI.HtmlControls.HtmlInputFile control on my
Webform that allows the user to find their CSV file, and I read that CSV file
into a Data Table. I then send that Data Table in my Class back to my ASPX,
and store it in a Data View then bind my DataGrid to that Data View.

I thought this would work without uploading the file to the Server, because
I didn't want to manage these files on the Server when I was done with them.



Eliyahu Goldin said:
You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


SAL said:
Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net
so
if you have some sample code I can look at that would be great.

Thanks,
 
J

Jay

Save your file in the database with an extra argument so it's not shown
by defailt (status var) or save the file on the server linked to the
client's IP address
 
J

Jeff

You can also upload the file to the server to do all that you want to
do with it and then delete it as soon as your finished using it or when
the session ends.
Currently I have a System.Web.UI.HtmlControls.HtmlInputFile control on my
Webform that allows the user to find their CSV file, and I read that CSV file
into a Data Table. I then send that Data Table in my Class back to my ASPX,
and store it in a Data View then bind my DataGrid to that Data View.

I thought this would work without uploading the file to the Server, because
I didn't want to manage these files on the Server when I was done with them.



Eliyahu Goldin said:
You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


SAL said:
Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net
so
if you have some sample code I can look at that would be great.

Thanks,
 
G

Guest

Hi Jay,

How would I save the file on the server linked to the client's IP address?

I'm fairly new at C# and ASP.net, so if you have a code snippet I can look
at that would be great.

Would this file automatically be dispose of when the client existed their
browser or would I still need to manage this file and delete it when I was
done with it?
 
X

xAvailx

What you describe sounds like it should work.

What exactly isn't working about it?

How are you converting the CSV to DataTable?

Here is an example of what you want to do using a CSV reader 3rd party
library (there are other ways..but you asked for source code example).

http://www.csvreader.com/csv_samples.php

Note that instead of saving to the database, you would send the data
table into your class as you describe in your post.

HTH.

Currently I have a System.Web.UI.HtmlControls.HtmlInputFile control on my
Webform that allows the user to find their CSV file, and I read that CSV file
into a Data Table. I then send that Data Table in my Class back to my ASPX,
and store it in a Data View then bind my DataGrid to that Data View.

I thought this would work without uploading the file to the Server, because
I didn't want to manage these files on the Server when I was done with them.



Eliyahu Goldin said:
You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


SAL said:
Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net
so
if you have some sample code I can look at that would be great.

Thanks,
 
G

Guest

I am using the that snippet code you pointed me to in my Webform.

As for what exactly isn't working, it assume the file the user selected at
the client was uploaded to the server, and gives a general error message that
says something like the path to the file you specified doesn't exist.

I just assumed that if I read the CSV file from the Client into a Data
Table, that the Data Table reference with all it's data would have been
passed to the server, instead of trying to find the CSV file on the Server.

xAvailx said:
What you describe sounds like it should work.

What exactly isn't working about it?

How are you converting the CSV to DataTable?

Here is an example of what you want to do using a CSV reader 3rd party
library (there are other ways..but you asked for source code example).

http://www.csvreader.com/csv_samples.php

Note that instead of saving to the database, you would send the data
table into your class as you describe in your post.

HTH.

Currently I have a System.Web.UI.HtmlControls.HtmlInputFile control on my
Webform that allows the user to find their CSV file, and I read that CSV file
into a Data Table. I then send that Data Table in my Class back to my ASPX,
and store it in a Data View then bind my DataGrid to that Data View.

I thought this would work without uploading the file to the Server, because
I didn't want to manage these files on the Server when I was done with them.



Eliyahu Goldin said:
You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net
so
if you have some sample code I can look at that would be great.

Thanks,
 
X

xAvailx

So, you are using THAT 3rd party library?

Can you post a simple program that demonstrates the problem and
indicate which line is causing the error with the exact error message?
(http://www.pobox.com/~skeet/csharp/complete.html)

It sounds like your problem is with uploading the file and not the CSV
file conversion.

I am using the that snippet code you pointed me to in my Webform.

As for what exactly isn't working, it assume the file the user selected at
the client was uploaded to the server, and gives a general error message that
says something like the path to the file you specified doesn't exist.

I just assumed that if I read the CSV file from the Client into a Data
Table, that the Data Table reference with all it's data would have been
passed to the server, instead of trying to find the CSV file on the Server.

xAvailx said:
What you describe sounds like it should work.

What exactly isn't working about it?

How are you converting the CSV to DataTable?

Here is an example of what you want to do using a CSV reader 3rd party
library (there are other ways..but you asked for source code example).

http://www.csvreader.com/csv_samples.php

Note that instead of saving to the database, you would send the data
table into your class as you describe in your post.

HTH.

Currently I have a System.Web.UI.HtmlControls.HtmlInputFile control on my
Webform that allows the user to find their CSV file, and I read that CSV file
into a Data Table. I then send that Data Table in my Class back to my ASPX,
and store it in a Data View then bind my DataGrid to that Data View.

I thought this would work without uploading the file to the Server, because
I didn't want to manage these files on the Server when I was done with them.



:

You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net
so
if you have some sample code I can look at that would be great.

Thanks,
 
G

Guest

You are correct on both counts. I do not have a problem reading the file with
the 3rd party CSVReader.

My Webform works fine IF I save the file to the Server for the CSVReader to
work.

I want to read the CSV file at the Client, load the Data Table from the CSV
file at the Client, then pass the Data Table back to my Webform from my
library class. After which, store this Data Table reference in my a Data
view and bind that Data View to my Data Grid.

From the post I've read, it sounds like I can't do this. It sounds like I
have not choice to to save the file server, then delete it from the server
when I'm done with it which is what I was trying to avoid.

xAvailx said:
So, you are using THAT 3rd party library?

Can you post a simple program that demonstrates the problem and
indicate which line is causing the error with the exact error message?
(http://www.pobox.com/~skeet/csharp/complete.html)

It sounds like your problem is with uploading the file and not the CSV
file conversion.

I am using the that snippet code you pointed me to in my Webform.

As for what exactly isn't working, it assume the file the user selected at
the client was uploaded to the server, and gives a general error message that
says something like the path to the file you specified doesn't exist.

I just assumed that if I read the CSV file from the Client into a Data
Table, that the Data Table reference with all it's data would have been
passed to the server, instead of trying to find the CSV file on the Server.

xAvailx said:
What you describe sounds like it should work.

What exactly isn't working about it?

How are you converting the CSV to DataTable?

Here is an example of what you want to do using a CSV reader 3rd party
library (there are other ways..but you asked for source code example).

http://www.csvreader.com/csv_samples.php

Note that instead of saving to the database, you would send the data
table into your class as you describe in your post.

HTH.


SAL wrote:
Currently I have a System.Web.UI.HtmlControls.HtmlInputFile control on my
Webform that allows the user to find their CSV file, and I read that CSV file
into a Data Table. I then send that Data Table in my Class back to my ASPX,
and store it in a Data View then bind my DataGrid to that Data View.

I thought this would work without uploading the file to the Server, because
I didn't want to manage these files on the Server when I was done with them.



:

You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net
so
if you have some sample code I can look at that would be great.

Thanks,
 
X

xAvailx

I want to read the CSV file at the Client, load the Data Table from the CSV
file at the Client, then pass the Data Table back to my Webform from my

library class. <<

I don't think this is possible in the way you describe, but that
doesn't mean you have to store on server or database.

When you upload the file, it is stored in the InputStream property of
the HttpPostedFile object. At that point, you can convert to the
datatable or manipulate the stream as needed in your class or persist
for further manipulation (probably in session or view state).

The example I was pointing at is "Upload CSV file to SQL Server using
FileUpload, CsvDataReader, and SqlBulkCopy in .Net 2.0"

I don't have that library, but based on the example code they have, the
(pseudo) code would look something like this..

protected void uploadButton_Click(object sender, EventArgs e)
{
using (CsvDataReader uploadedFile = new
CsvDataReader(fileUpload.PostedFile.InputStream, Encoding.Default))
{
DataTable myDataTable = new DataTable();

myDataTable.Load(uploadedFile.ReadToEnd(True));

YourClass anInstanceOfYourClass = YourClass.New(myDataTable);

//Manipulate your class or persist...
anInstanceOfYourClass.DoWhatever();

}
}

You are still going to have to persist your class (session, view state,
or somewhere...) if you are to further manipulate in between page
calls.

I don't know your specific requirements, but if all you are worried
about is "maintaining" the uploaded files, and the above doesn't work
in your scenario (it is worth noting that it will probably consume a
lot of memory if you are going to persist in session), then you can
just store the file in a datastore and create a scheduled job to clean
up the data. You would probably use the session id to tie back to the
session that uploaded the file.

HTH.
You are correct on both counts. I do not have a problem reading the file with
the 3rd party CSVReader.

My Webform works fine IF I save the file to the Server for the CSVReader to
work.

I want to read the CSV file at the Client, load the Data Table from the CSV
file at the Client, then pass the Data Table back to my Webform from my
library class. After which, store this Data Table reference in my a Data
view and bind that Data View to my Data Grid.

From the post I've read, it sounds like I can't do this. It sounds like I
have not choice to to save the file server, then delete it from the server
when I'm done with it which is what I was trying to avoid.

xAvailx said:
So, you are using THAT 3rd party library?

Can you post a simple program that demonstrates the problem and
indicate which line is causing the error with the exact error message?
(http://www.pobox.com/~skeet/csharp/complete.html)

It sounds like your problem is with uploading the file and not the CSV
file conversion.

I am using the that snippet code you pointed me to in my Webform.

As for what exactly isn't working, it assume the file the user selected at
the client was uploaded to the server, and gives a general error message that
says something like the path to the file you specified doesn't exist.

I just assumed that if I read the CSV file from the Client into a Data
Table, that the Data Table reference with all it's data would have been
passed to the server, instead of trying to find the CSV file on the Server.

:

What you describe sounds like it should work.

What exactly isn't working about it?

How are you converting the CSV to DataTable?

Here is an example of what you want to do using a CSV reader 3rd party
library (there are other ways..but you asked for source code example).

http://www.csvreader.com/csv_samples.php

Note that instead of saving to the database, you would send the data
table into your class as you describe in your post.

HTH.


SAL wrote:
Currently I have a System.Web.UI.HtmlControls.HtmlInputFile control on my
Webform that allows the user to find their CSV file, and I read that CSV file
into a Data Table. I then send that Data Table in my Class back to my ASPX,
and store it in a Data View then bind my DataGrid to that Data View.

I thought this would work without uploading the file to the Server, because
I didn't want to manage these files on the Server when I was done with them.



:

You can find a file on the client's file system if you use WSH (Windows
Scripting Host). You would need to set special security on each client
browser.

Asp.Net databinding is a pure server-side functionality. You can't do it on
client.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hello,

Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?

I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.

Has anyone done this before? If so, how do I do it? I'm new to ASP.net
so
if you have some sample code I can look at that would be great.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top