Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to Download binary (.txt file) data from sql via web service
    primarykey
    data
    text
    <p>i have successfully uploaded and downloaded a txt file via binary to the local sql with this code here.</p> <pre><code>byte[] FileData = File.ReadAllBytes(txtUpload.Text); SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=WCFTest;Integrated Security=True;Pooling=False"); con.Open(); SqlCommand cmd = new SqlCommand(@"INSERT into upload (Path,Data,Username,Email,Price,Description)values(@path,@data,@username,@email,@price,@description)", con); cmd.Parameters.Add(new SqlParameter("@path", (object)txtUpload.Text)); cmd.Parameters.Add(new SqlParameter("@data", (object)FileData)); cmd.Parameters.Add(new SqlParameter("@username", (object)txtSellUsername.Text)); cmd.Parameters.Add(new SqlParameter("@email", (object)txtSellEmail.Text)); cmd.Parameters.Add(new SqlParameter("@price", (object)txtSellPrice.Text)); cmd.Parameters.Add(new SqlParameter("@description", (object)txtSellDescription.Text)); cmd.ExecuteNonQuery(); con.Close(); </code></pre> <p>and Downloaded like this</p> <pre><code>FileStream FS = null; byte[] dbbyte; SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=WCFTest;Integrated Security=True;Pooling=False"); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM upload where Id='" + txtBuyId.Text + "'", con); da = new SqlDataAdapter(cmd); dt = new DataTable(); da.Fill(dt); con.Close(); if (dt.Rows.Count &gt; 0) { dbbyte = (byte[])dt.Rows[0]["Data"]; string filepath = (rootDirectory + "\\Profiles\\" + txtBuyPrice.Text.ToString() + ".txt" ); FS = new FileStream(filepath, System.IO.FileMode.Create); FS.Write(dbbyte, 0, dbbyte.Length); FS.Close(); con.Close(); }*/ </code></pre> <p>From this i have worked out how to upload via the web service like this</p> <pre><code> try { byte[] FileData = File.ReadAllBytes(txtUpload.Text); UserDetailsService.SellProfiles sellprofiles = new UserDetailsService.SellProfiles(); sellprofiles.Upload = txtUpload.Text; sellprofiles.Upload2 = FileData; sellprofiles.Username = txtSellUsername.Text; sellprofiles.Email = txtSellEmail.Text; sellprofiles.Price = txtSellPrice.Text; sellprofiles.Name = txtSellProfileName.Text; sellprofiles.Description = txtSellDescription.Text; obj.InsertSellingProfiles(sellprofiles); DialogResult dialogResult = MessageBox.Show("Your profile has been successfully uploaded!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dialogResult == DialogResult.OK) { new Menu().Show(); this.Close(); } </code></pre> <p>But now i have tried a various amount of ways to download the binary data from the web service but i am struggling to find a solution!</p> <p>Can anyone help me with this? Hopefully my code can help someone more experienced to help me find a solution</p> <p>Thank you</p> <p>I have attempted to download from service like this:</p> <pre><code> UserDetailsService.Service1Client obj1 = new UserDetailsService.Service1Client(); byte[] dbbyte; FileStream FS; UserDetailsService.Service1Client sc = new UserDetailsService.Service1Client(); if (sc.CheckIfProfileExists(txtBuyId.Text, txtBuyProduct.Text)) { BuyProfile.Id = txtBuyId.Text; BuyProfile.Name = txtBuyProduct.Text; DataSet ds = new DataSet(); DataTable dt = new DataTable(); dt = obj1.DownLoadProfile(txtBuyId.Text, txtBuyProduct.Text); if (dt.Rows.Count &gt; 0) { dbbyte = (byte[])dt.Rows[0]["Data"]; string filepath = (rootDirectory + "\\Profiles\\" + txtBuyProduct.Text.ToString() + ".txt"); FS = new FileStream(filepath, System.IO.FileMode.Create); FS.Write(dbbyte, 0, dbbyte.Length); FS.Close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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