このコードを使用して、ローカルSQLにバイナリ経由でtxtファイルを正常にアップロードおよびダウンロードしました。
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();
とこのようにダウンロード
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 > 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();
}*/
これから、このようなWebサービスを介してアップロードする方法を考え出しました
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();
}
しかし今、Web サービスからバイナリ データをダウンロードするさまざまな方法を試しましたが、解決策を見つけるのに苦労しています。
誰でもこれで私を助けることができますか?うまくいけば、私のコードが経験豊富な誰かが解決策を見つけるのを助けるのに役立つことを願っています
ありがとうございました
次のようなサービスからダウンロードしようとしました:
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 > 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();