Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all, trying to upload files via asp.net C# webform from a mobile android phone.

it works fine on windows machine , but on the mobile android phone i get a microsoft os like path instead of the phone's path.

What I have tried:

C#
public void UpLoad(string imgName, string LocalFile)
        {
            WebClient client = new WebClient();
            NetworkCredential nc = new NetworkCredential(myuserName, myPassword);
            Uri addy = new Uri(myFTPServer+ imgName);
            client.Credentials = nc;
            client.UploadFile(addy, LocalFile);
        }


 protected void btnUpLoad_Click(object sender, EventArgs e)
    {
        clsFTP.clsImgProperty cFTP = new clsFTP.clsImgProperty();
       // string strPath = Path.GetFullPath(FLoadDoc.PostedFile.FileName);//FLoadDoc.PostedFile.FileName
        //string upDir = Path.Combine(Request.PhysicalApplicationPath, @"/DCIM/Camera/");
        //string strPath = @"~/DCIM/Camera/" + Path.GetFileName(FLoadDoc.FileName);
        string strPath = @"\storage\sdcard0\DCIM\Camera\" + FLoadDoc.FileName;
        // / storage / sdcard0 / DCIM
        //‏‏מחשב זה\Galaxy A5 (2017)\Phone\DCIM\Camera
        cFTP.UpLoad(Path.GetFileName(FLoadDoc.FileName), strPath);//where to , from where
    }
Posted
Updated 5-Aug-18 8:33am
v2
Comments
Dave Kreskowiak 24-Jul-18 20:36pm    
Your code suggests that you seem to the think that ASP.NET code runs on the client. That's not true. It runs entirely on the server, never the client, i.e.: your Android device.

So, it seems you're trying to do an FTP upload from the web server ... tooooo ???
Member 12793964 25-Jul-18 8:54am    
thank you for your reply. i checked what you said ,and looked deeper in to WebClient
and WebCliet.UploadFile at msdn and it is described as "Sends a local file to the resource and returns a Byte array containing any response.". so this operated on the client side. maybe webclient dos not support android 7.0 os?
Dave Kreskowiak 25-Jul-18 8:58am    
NONE of your ASP.NET code runs on your Android device. ASP.NET apps run entirely on a web server. You DO have a web server, correct? You have published your code to this server, correct?

Member 12793964 25-Jul-18 10:14am    
yes i have on,i am trying to enhance my website, so is there any code that i can use to upload a file from my mobile - client side to the server?
in a WinForm application on a pc it works and uploads files ok.

ASP.NET code just generates HTML and javascript and sends that to the client device, your Android.

Look into the FileUpload control[^], and documentation[^].

That control generates a simple UI and the corresponding client-side javascript code to handle selecting and upload a file to your ASP.NET code on the server.
 
Share this answer
 
Comments
Member 12793964 25-Jul-18 18:00pm    
what about credetials?
Dave Kreskowiak 25-Jul-18 18:24pm    
What about them? If you need to login to the web site, handle the authentication on the page that presents the UI for uploading the file.
thank you , fileupload - worked
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900