我有一個wpf員工創建窗口,我可以在其中創建名字,姓氏等基本信息,這會在我的REST Web服務中創建員工。舉個例子:Excel文檔內容到webservice
客戶端:
private void CreateStaffMember_Click(object sender, RoutedEventArgs e)
{
string uri = "http://localhost:8001/Service/Staff";
StringBuilder sb = new StringBuilder();
sb.Append("<Staff>");
sb.AppendLine("<FirstName>" + this.textBox1.Text + "</FirstName>");
sb.AppendLine("<LastName>" + this.textBox2.Text + "</LastName>");
sb.AppendLine("<Password>" + this.passwordBox1.Password + "</Password>");
sb.AppendLine("</Staff>");
string NewStudent = sb.ToString();
byte[] arr = Encoding.UTF8.GetBytes(NewStudent);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "application/xml";
req.ContentLength = arr.Length;
Stream reqStrm = req.GetRequestStream();
reqStrm.Write(arr, 0, arr.Length);
reqStrm.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
MessageBox.Show("Staff Creation: Status " + resp.StatusDescription);
reqStrm.Close();
resp.Close();
}
Web服務端:
#region POST
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/Staff")]
void AddStaff(Staff staff);
#endregion
public void AddStaff(Staff staff)
{
staff.StaffID = (++eCount).ToString();
staff.Salt = GenerateSalt();
byte[] passwordHash = Hash(staff.Password, staff.Salt);
staff.Password = Convert.ToBase64String(passwordHash);
staffmembers.Add(staff);
}
所有在那邊很好,但是我希望 「進口」 的員工從Excel電子表格的詳細信息,不確定如果導入是正確的單詞,但我想採取在這樣的電子表格中包含的名字和姓氏,並將它們添加到客戶端wpf應用程序的Web服務。
我該怎麼辦呢?我有我的打開文件對話框:
private void Import_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dlg.FileName;
}
}
所以,我打開我的excel電子表格,然後我將如何去走的是內部內容,並將其發送到Web服務?真的停留在代碼或如何去關於它:/
只是尋找一種自動添加工作人員的方式,而不是手動輸入名稱,但作爲員工Excel文檔可以命名爲任何我想要的打開文件對話框。裏面的結構將始終是相同的名字,然後是姓氏。
這絕不會回答你的問題......但將數據存儲在數據庫中會不會容易得多? – Pynner