473,804 Members | 3,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting a filename to a unc filename

I want to convert a filename to it's equivalent unc filename. First, is there
a C# call that i can use that will do it directly?

If not then I will look at the Directory.FullP ath() of a file and detemine
it it has a VolumeSeparator Character in it. If so I will then look at the
DriveInfo for that volume and determine if it is a network drive. If not then
I will replace the volume specifier with a unc name like \\192.168.1.2\c $\...

However, what can I use to translate the the network volume drive into a
sharename that I can use to form the unc name? Is there a method for that
somewhere?

thanks
Jun 27 '08 #1
1 2502
On May 27, 9:30*pm, Brian <Br...@discussi ons.microsoft.c omwrote:
I want to convert a filename to it's equivalent unc filename. First, is there
a C# call that i can use that will do it directly?

If not then I will look at the Directory.FullP ath() of a file and detemine
it it has a VolumeSeparator Character in it. If so I will then look at the
DriveInfo for that volume and determine if it is a network drive. If not then
I will replace the volume specifier with a unc name like \\192.168.1.2\c $\...

However, what can I use to translate the the network volume drive into a
sharename that I can use to form the unc name? Is there a method for that
somewhere?

thanks
hi,
you may use this code to translate a network drive to the unc name of
the share:

// needs reference to "C:\WINDOWS\sys tem32\scrrun.dl l"

using System;
using System.Runtime. InteropServices ;

namespace Sharename
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Scripting.FileS ystemObject fileSystemObj = null;
Scripting.Drive drive = null;

try
{
fileSystemObj = new Scripting.FileS ystemObject();
drive = fileSystemObj.G etDrive("I:");
Console.WriteLi ne("Share: {0}\n", drive.ShareName );
}
finally
{
if (drive != null)
Marshal.Release ComObject(drive );
if (fileSystemObj != null)
Marshal.Release ComObject(fileS ystemObj);
}
}
}
}

Sorry for the late reply but I'm a little bit behind to read the posts
of this group (something about 5000 unread posts or so).
Jul 8 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
2192
by: Nate | last post by:
I am working on an Oakley parser and want to call an fopen function to read in the log file. I can use this to read the file, but only if I pass a "const char" variable to fopen. Since I would like the end user to specify the name of the log file, I have a scanf in there to allow the user to do so, but it isn't a const at that point. I have seen reference to calls like static_cast, dynamic_cast and reinterpret_cast in C that will allow...
1
2548
by: Kieran Benton | last post by:
Hi, Sorry to post this, I feel like a right fool but Im under serious time pressure! Afraid I'm a newbie to managed C++ (Ive had to resort to it as Im wrapping some COM objects for C# use). Any ideas how to get this working? void Configure(int port,String* filename,int maxclients) { //const WCHAR* fn = const_cast<__wchar_t*>(PtrToStringChars(filename));
4
5154
by: kls_kumar | last post by:
Hi All, I wrote a sample application to extract the messages and attachments from a .pst file using VB.Net which is working fine. Now i am trying to web service enable this and when i added an operation in .asmx File <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ Public Function extractPST(ByVal fileName As String) As String Dim readPST As ReadPST readPST = New ReadPST
11
6087
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for dicts with larger no. of features. Now i want to check each pair to see if they are connected...element of this pair will be one from the first list and one from the second....e.g for 'ab' i want to check if 1 and 3 are connected,then 1 and...
0
2034
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual Studio 2005). The problem occurred when I trying to opening and reading file: ============= C++ ============= void LoadSourceFile(char * fileName, unsigned char * data, int length)
1
1709
by: atlkhan | last post by:
Hi I am using strcpy(filename, banner.c_str()); to convert banner which of string type to a character string filename. In banner there is a string name which I have read from file using getline. e.g banner =john
1
1531
by: ahobart | last post by:
Hello, I have this code in C# and it works perfect: protected string GetUniqueName(string filename) { string temp = filename; for (int x=1; System.IO.File.Exists(temp); x++){ temp = filename.Substring(0, filename.LastIndexOf(".")) + x + filename.Substring(filename.LastIndexOf(".")); } return new System.IO.FileInfo(temp).Name; }
0
1933
by: clinnebur | last post by:
We have an ASP.NET web application (C#) that copies videos from a CCTV truck to a Linux server. What I am trying to do is convert the .AVI videos(which is how they are created on the truck) to .WMV in my C# code using Windows Media Encoder. I have a virtual directory to the truck location of the videos. I also have a virtual directory created to the Linux box. The application resides on a Windows Server 2003 and I am using VS 2005, .NET...
1
2809
by: David Buckley | last post by:
Does anyone have any example code of converting any type of video to flash video at all using asp.net 2.0 c# web applications. God Bless
1
2512
by: nadasgh | last post by:
Hi, PLease can anyone help me in solving my problem.. Thanks in advance... I am using asp.net 2.0 c# , the project that I am working on is uploading a document and saving it into database (SQL Server 2005). The error message that i am getting when executing the query in the InsertFile function and the UpdateFile function is:" No mapping exists from object type System .Web.HttpinputStream to a known Managed provider native type" I am...
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10593
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.