Click here to Skip to main content
15,892,517 members
Home / Discussions / C#
   

C#

 
AnswerRe: commands don't work??? Pin
Michael Potter12-Jan-06 5:10
Michael Potter12-Jan-06 5:10 
QuestionDataSet and Database Pin
Sasuko12-Jan-06 4:53
Sasuko12-Jan-06 4:53 
AnswerRe: DataSet and Database Pin
harryjo12-Jan-06 5:09
harryjo12-Jan-06 5:09 
GeneralRe: DataSet and Database Pin
Sasuko12-Jan-06 12:35
Sasuko12-Jan-06 12:35 
GeneralRe: DataSet and Database Pin
Daniel Santillanes12-Jan-06 13:08
professionalDaniel Santillanes12-Jan-06 13:08 
QuestionRadioButtonList Control - Problems getting value from listItems programmatically added - HELP! Pin
Alan R. Smith12-Jan-06 4:43
Alan R. Smith12-Jan-06 4:43 
QuestionFinding strings in a project Pin
MartinSmith12-Jan-06 3:51
MartinSmith12-Jan-06 3:51 
QuestionMapping a Drive at runtime Pin
exhaulted12-Jan-06 2:49
exhaulted12-Jan-06 2:49 
Hi all, i'm trying to access files on a networked dirve using the UNC name "\\myServer\d$".
Unfortunately if i dont have a drive mapped when i try to find files on the server i get an IOException saying that the directory doesn't exist.

I found some useful comments at the bottom of an article talking about using WHScript's MapNetworkDrive method. This sounds good but i can't get it to work. Here's my code which is only slightly different from the comment on the article.
public void InvokeComMember(string member, params object[] param)
{
	Type type;
	Object o;
	try
	{
		type = Type.GetTypeFromProgID("WScript.Network");
		o = Activator.CreateInstance(type);
		type.InvokeMember(member, BindingFlags.InvokeMethod, null, o, param);
	}
	catch{}
	finally
	{
		type = null;
		o = null;
	}
}


The paramaters being passed in are...
InvokeComMember("MapNetworkDrive", @"\\" + serverName + @"\d$", "", false, userName, password);

serverName, userName and password are all strings that i've double checked are correct.

The exception i get is...
System.Exception: Invoke Com Error ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: The network name cannot be found.

When i type the same \\"serverName"\d$ into the run window i get a connection fine so i know the serverName variable is correct.

Anyone know either...
1. What i'm doing wrong with this or
2. Another way of getting at the files on the UNC'd server.


Cheers

Kev

-- modified at 8:49 Thursday 12th January, 2006
AnswerRe: Mapping a Drive at runtime Pin
Koushik Biswas12-Jan-06 6:07
Koushik Biswas12-Jan-06 6:07 
GeneralRe: Mapping a Drive at runtime Pin
exhaulted12-Jan-06 9:08
exhaulted12-Jan-06 9:08 
Questionproblem with datagrid.unselect Pin
melanieab12-Jan-06 2:41
melanieab12-Jan-06 2:41 
AnswerRe: problem with datagrid.unselect Pin
exhaulted12-Jan-06 3:17
exhaulted12-Jan-06 3:17 
QuestionGenerics Problem Pin
Kevin McFarlane12-Jan-06 1:41
Kevin McFarlane12-Jan-06 1:41 
AnswerRe: Generics Problem Pin
mav.northwind12-Jan-06 5:18
mav.northwind12-Jan-06 5:18 
GeneralRe: Generics Problem Pin
Kevin McFarlane12-Jan-06 7:44
Kevin McFarlane12-Jan-06 7:44 
Questionplease correct my query Pin
Sasuko12-Jan-06 1:18
Sasuko12-Jan-06 1:18 
AnswerRe: please correct my query Pin
Colin Angus Mackay12-Jan-06 1:48
Colin Angus Mackay12-Jan-06 1:48 
GeneralRe: please correct my query Pin
Sasuko12-Jan-06 2:40
Sasuko12-Jan-06 2:40 
GeneralRe: please correct my query Pin
Colin Angus Mackay12-Jan-06 2:50
Colin Angus Mackay12-Jan-06 2:50 
AnswerRe: please correct my query Pin
Guffa12-Jan-06 2:23
Guffa12-Jan-06 2:23 
AnswerRe: please correct my query Pin
Sasuko12-Jan-06 4:49
Sasuko12-Jan-06 4:49 
QuestionUsing String.Replace method with variables Pin
sohne11-Jan-06 23:11
sohne11-Jan-06 23:11 
AnswerRe: Using String.Replace method with variables Pin
Colin Angus Mackay11-Jan-06 23:23
Colin Angus Mackay11-Jan-06 23:23 
QuestionImporting contacts to Microsoft Outlook with C# Pin
Starchild200511-Jan-06 21:59
Starchild200511-Jan-06 21:59 
QuestionHow can be a Transparent panel control can be created Pin
Shashidharreddy11-Jan-06 21:52
Shashidharreddy11-Jan-06 21:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.