Juliano
Juliano

Reputation: 153

Network Share/SMB Client

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

Answers (3)

josua josh
josua josh

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:

  1. Create a new profile name on windows.
  2. Give that new profile name a password. (must have a password to share something)
  3. Give the folder or files permission to share access to that profile with password.
  4. 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

Xavier J
Xavier J

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

tantonj
tantonj

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

Related Questions