WINMOBILE upload file from C # to php webservice

I need to upload a file using C # from a Windows mobile application to a website. It runs PHP as a web service on the other hand, although I think it really is not, if there is another way to get the file there. However, ASP server support is not available. My problem is really not in PHP, it is C # mobile code.

In addition, System.net.WebClient does NOT exist in a compact structure, unfortunately this simple solution has disappeared.

Let me apologize in advance because I know this is a relatively frequently asked question, but I just can't find the answer. I spent a lot of time on this particular problem without a solution, so any help would be greatly appreciated. Many thanks!

+3
source share
2 answers

Have a look at this article Improving the HTTP Communications of the .NET Compact Framework with HttpWebRequest and Custom ASP.NET Providers on MSDN. It is specific to ASP technology, but the Compact Framework remains unchanged. It mainly uses HttpWebRequest with the PUT method. If you are not allowed to do this on the server, you need to create a sequence of POST requests yourself and process them accordingly.

+2
source

The following code snippet can help solve the problem that we are discussing here. Please ignore this if it is not relevant to this topic.

, . , , .

"" :

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 Framework 2.0

MS SQL Server 2000 MS SQL Server 2005.

0

All Articles