Reputation: 153
I'm trying to read a file from a android phone to a Windows share. I'm using now the StreamWriter, like below:
StreamWriter outfile = new StreamWriter(@"\\10.16.68.253\sam\AllTxtFiles.txt");
outfile.WriteLine("TESTGENREOIADNIWAN");
But i get a Access Denied. I already added the permission to the manifest. And i tested the share using the ES File Explorer (with everyone access). I used the same lines of code on a WPF app and works fine, so my problem is in Android app.
I already tried to change the connection string like the ES, smb://10.16.68.253/sam/AllTxtFiles.txt, but no luck.
Anyone accomplished this ?
Tks !
Upvotes: 8
Views: 11032
Reputation: 88
Are you sure you are able to read/write files using ESFileExplorer with EVERYONE ACCESS permissions? Windows is a very secured OS. You need to grant permissions to a particular profile. Example:
Access the folder or files using smb along with the profile username and password. Such as "smb://username:password@local ip"
StreamWriter outfile = new StreamWriter(smb:\\username:password@"\\10.16.68.253\sam\AllTxtFiles.txt");
outfile.WriteLine("TESTGENREOIADNIWAN");
Upvotes: 0
Reputation: 4628
You have to make sure the connection to the SMB share is authenticated before trying to access any files. You have to use API calls to do this, because this stuff is done in the Win32 layer outside of managed code.
Here's a start:
http://www.pinvoke.net/default.aspx/mpr/WNetAddConnection.html
Upvotes: 1
Reputation: 444
for me I had to set up the string like this "smb://username:password@local ip/" for the root of my server's Windows share.
Upvotes: 1