2008-11-20 41 views
3

我需要使用C#從Windows Mobile應用程序上傳文件到網站。它運行PHP作爲另一方面的web服務,但我想如果有另一種方式可以在那裏獲取文件,那真的不需要。然而,沒有服務器端ASP支持。我的問題實際上不是PHP,而是移動C#代碼。WINMOBILE將文件從C#上傳到php webservice

另外,System.net.WebClient在緊湊框架中不存在,所以不幸的是,這個簡單的解決方案已經消失。

讓我先提前道歉,因爲我知道這是一個比較常見的問題,但我似乎無法找到答案。我在這個特殊的問題上花費了不少時間,沒有解決方案,所以任何幫助都將非常值得讚賞。非常感謝!

+0

這不是一個普遍的問題。與C#中的ASP.NET web服務交談是一個蛋糕,這很難。 – MusiGenesis 2008-11-20 22:16:34

回答

0

以下代碼片段可能有助於解決我們在此討論的問題。 如果與此主題無關​​,請忽略此內容。

簡要說明如何使用文章或代碼。類名稱,方法和屬性,任何技巧或提示。代碼

塊應設置爲風格的 「格式化」 是這樣的:

示例代碼

using System.Data; 
using System.Data.Sql 
using System.Data.SqlClient; 
using System.Web; 
using System.Web.Services; 

public class FileUploader: System.Web.Services.WebService { 
    SqlConnection myConnection = new SqlConnection("Data Source=server name ;Initial Catalog=database name; User ID=username; Password='password';"); 
    SqlCommand myCommand = new SqlCommand(); 
    string queryString = ""; 

public string UploadFile(byte[] f, string fileName) 
    { 
      // the byte array argument contains the content of the file 
      // the string argument contains the name and extension 
      // of the file passed in the byte array 

string nm = data[0]; 
string sn =data[1]; 
string bn =data[2]; 
string st = data[3]; 
byte img = Convert.Tobyte(img); 
myConnection.Open(); 
queryString = "INSERT INTO tablename(Name,SchemeName,BeneficiarName,Status,Photo)" 

+ "VALUES('" + nm + "','" + sn + "','"+ bn +"','" + st + "',@img,')"; 

myCommand.Parameters.AddWithValue("@img",f); 
myCommand.Connection = myConnection; 
myCommand.CommandType = CommandType.Text; myCommand.CommandText = queryString; int res = myCommand.ExecuteNonQuery(); myConnection.Close(); 

if (res > 0) 
{ 
    strres = "File Uploaded successfully"; } 

else 
{ 
    strres = "File not uploaded"; 
} 
return strres; 
} 

要求

的Visual Studio.Net 2005

.Net框架2.0

MS SQL Server 2000數據庫或MS SQL Server 2005 d atabase。

+0

你好SQL注入攻擊! – ctacke 2012-12-29 19:02:47