Note that there are some explanatory texts on larger screens.

plurals
  1. POCan the server use a file from a client without uploading it to the server? ASP.NET
    primarykey
    data
    text
    <p>I was wondering, at the moment, the client uploads a file to a directory on the server where the server can then use the file (csv file) to update a SQL database.</p> <p>Is that the only way the server can use that file? For it to first be uploaded to the server? Or can you use that file without uploading it to a directory of the server?</p> <p>(using visual studio 2012, C# and asp.net)</p> <p>Code update---</p> <p>asp Uploading the file. (I know the code can be cleaner an written better, but my testing code is never clean) </p> <pre><code> //Uplod file to the server FileUpload1.SaveAs(serverUploadDir + FileUpload1.FileName); //Use the Uploaded File to update the sql table dbConn.UploadCSVToSql(serverUploadDir + FileUpload1.FileName); </code></pre> <p>The UploadCSVToSql</p> <pre><code> public void UploadCSVToSql(string filepath) { //string filepath = "C:\\Copy of ABI Employee List.csv"; StreamReader sr = new StreamReader(filepath); string line = sr.ReadLine(); string[] value = line.Split(','); DataTable dt = new DataTable(); DataRow row; foreach (string dc in value) { dt.Columns.Add(new DataColumn(dc)); } while (!sr.EndOfStream) { value = sr.ReadLine().Split(','); if (value.Length == dt.Columns.Count) { row = dt.NewRow(); row.ItemArray = value; dt.Rows.Add(row); } } SqlBulkCopy bc = new SqlBulkCopy(conn.ConnectionString, SqlBulkCopyOptions.TableLock); bc.DestinationTableName = "MainDump"; bc.BatchSize = dt.Rows.Count; conn.Open(); bc.WriteToServer(dt); bc.Close(); conn.Close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload