Question Implementing WNetUseConnection

BOB.G

New member
Joined
Mar 29, 2017
Messages
4
Programming Experience
1-3
So... I am in the process of writing a program that requires remote access to a file on another machine in the same domain
without any mapping.
I have done some research on the Internet and came to the conclusion that the best way forward is to implement
Win32 API function WNetUseConnection found at the link below.

c# - How do I access a file share programattically - Stack Overflow

The only problem is, this example is divided into 3 sections with only 1 section recognizable.
I was wondering if someone could extend a helping hand in getting it implemented.

Below is my program listing with indication of where I would like to access the remote machine:-

namespace WindowsFormsApplication1
{
public partial class Form1 : Form{

public Form1(){
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e){
this.Close();
}

private void timer1_Tick(object sender, EventArgs e){
statusBar1.Panels[1].Text = DateTime.Now.ToString("hh:mm:ss");
statusBar1.Panels[0].Text = DateTime.Now.ToShortDateString();
}

private void Form1_Load(object sender, EventArgs e){
string path = @"G:\PhoneApps";
string filename = DateTime.Now.ToString("dd-MM-yyyy");
string controlfile = Path.Combine(path, filename + ".txt");

switch(File.Exists(controlfile)){

case true: statusBar1.Panels[2].Text = "Directory Located......";
break;
default: statusBar1.Panels[2].Text = "Downloading Directory......";
//check remote machine for controlfile here?.
// File.Create(controlfile);
break;
}
}
}
}


Thanks in advance
 
Jmcilhinney... I did copy and paste the section starting with [DllImport("Mpr.dll", EntryPoint...... into the form, but got some errors when I compiled it.
That was the main reason why I am seeking help, as I wasn't sure whether or not I was doing the right thing.
 
Back
Top Bottom