Upload picture from winmobile (C#) using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cyprus106
    New Member
    • Apr 2008
    • 31

    Upload picture from winmobile (C#) using php

    I know this is a commonly asked question, so sorry in advance, but even though it seems to be asked fairly frequently, I can't seem to find good code on it.

    Essentially, I just want to upload a file to my website (on site-side using PHP & post) in windows mobile. Can anyone help me out? Sorry for the brevity, if you want details just let me know.
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    What have you already tried?

    Comment

    • markmcgookin
      Recognized Expert Contributor
      • Dec 2006
      • 648

      #3
      Depending on your setup, a web service might be in order. If this is for Windows Mobile it is incredibly easy to add a web reference to a project that will accept something like a base64 string or byte[] to transfer your file, then your server side web service could read this in then create the file.

      Comment

      • Cyprus106
        New Member
        • Apr 2008
        • 31

        #4
        This is what I started, but I couldn't seem to get anything to happen...

        EDIT: Bear in mind I've completely winged this. Truthfully I just don't have a clue and this was more of a guess/codejacking. My plan, Mark, actually was to send a byte array to a php script that acted as a web service. Unfortunately, I've never dealt with file transfers and as such, I don't even know how to do that! lol I'm at ground zero.


        string localFile;
        string uploadUrl;


        Code:
                    try
                    {
        
                        FileStream rdr = new FileStream(localFile, FileMode.Open);
                        byte[] inData = new byte[4096];
                        int totbytes = 0;
                        MemoryStream postData = new MemoryStream();
                        int bytesRead = rdr.Read(inData, 0, inData.Length);
                        while (bytesRead > 0)
                        {
                            postData.Write(inData, 0, bytesRead);
                            bytesRead = rdr.Read(inData, 0, inData.Length);
                            totbytes += bytesRead;
                        }
                        rdr.Close();
                        postData.Position = 0;
                        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
                        req.Method = "POST";
                        req.ContentLength = (long)postData.Length;
                        using (Stream s = req.GetRequestStream())
                        {
                            s.Write(postData.ToArray(), 0, (int)postData.Length);
                            postData.Close();
                        }
                        WebResponse resp = req.GetResponse();
                        resp.Close();
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                    }
        Last edited by Cyprus106; Nov 14 '08, 03:02 PM. Reason: forgot something

        Comment

        • Cyprus106
          New Member
          • Apr 2008
          • 31

          #5
          If anybody has any ideas, I would still appreciate it. I'm sadly still kind of stuck on this problem.

          Comment

          • markmcgookin
            Recognized Expert Contributor
            • Dec 2006
            • 648

            #6
            Cyprus,

            The easiest way to add a web service call to any .Net application is to make sre that the web service is externally exposed (i.e. available to connections) then use visual studio to add a web reference to your web service. Then all you have to do is create an instance of your web service then call your web method. It saves you manually invoking http requests etc.

            Comment

            Working...