-1
我把這個直接的一個按鈕,如下所示:上傳XML直接到ftp
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("Login");
XmlElement id = doc.CreateElement("id");
id.SetAttribute("userName", usernameTxb.Text);
id.SetAttribute("passWord", passwordTxb.Text);
XmlElement name = doc.CreateElement("Name");
name.InnerText = nameTxb.Text;
XmlElement age = doc.CreateElement("Age");
age.InnerText = ageTxb.Text;
XmlElement Country = doc.CreateElement("Country");
Country.InnerText = countryTxb.Text;
id.AppendChild(name);
id.AppendChild(age);
id.AppendChild(Country);
root.AppendChild(id);
doc.AppendChild(root);
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://users.skynet.be");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = false;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("fa490002", "password");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader();
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
MessageBox.Show("Created SuccesFully!");
this.Close();
,但我總是得到StreamReader的路徑的錯誤,我需要什麼的地方呢? 美化是,創建一個帳戶,當我按下按鈕,一個xml文件被保存到,ftp://users.skynet.be/testxml/ 文件名是從usernameTxb.Text +「.xml」。
它顯示了一個錯誤,有沒有construtors thath取0 argruments – 2011-01-14 11:55:07