Hello all,
I'm trying to get the UNC path of a mapped network folder, but it somehow
doesn't work. Below is my code, and I really hope that some can help me on
this by pointing out what I did wrong. I greatly appreciate your help.
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Imports Scripting.FileSystemObjectClass
Imports System.IO.Path
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
----------------------------------------------------------------------------------------------------
Private Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
sbRemoteName As StringBuilder, ByRef cbRemoteName As Integer) As Integer
-----------------------------------------------------------------------------------------------------------
Public Function GetUNCFromMappedDrive(ByVal driveLetter As String) As String
Dim StrUNC As New StringBuilder(256)
If WNetGetConnection32(driveLetter, StrUNC, 256) > 0 Then
'Not a mapped drive
StrUNC.Append(driveLetter)
End If
Return String.Copy(StrUNC.ToString.TrimEnd)
End Function
---------------------------------------------------------------------------------------------------
'Getting filename, file path & current username
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ofDlg As New OpenFileDialog
With ofDlg
'Filter for JPG files
.Filter = "Image Files (*.jpg)|*.jpg"
If .ShowDialog(Me) = DialogResult.OK Then
'Get filename
TextBox2.Text = IO.Path.GetFileName(.FileName)
'Get file path
TextBox3.Text = GetDirectoryName(.FileName)
End If
End With
'Get current username
TextBox1.Text = GetCurrent.Name
'Get the UNC path of the file
TextBox4.Text = GetUNCFromMappedDrive(TextBox3.Text.Substring(0, 3))
ofDlg.Dispose()
End Sub
End Class 3 4122
Someone posted the below code on this newsgroup..it might work but I haven't
tried it.
Public Declare Function WNetGetConnection Lib "mpr.dll" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, ByRef cbRemoteName As Integer)
As Integer
Sub Main()
Dim ret As Integer
Dim out As String = New String(" ", 260)
Dim len As Integer = 260
ret = WNetGetConnection("Q:", out, len)
Console.WriteLine(out)
End Sub
--
Dennis in Houston
"Stanav" wrote: Hello all, I'm trying to get the UNC path of a mapped network folder, but it somehow doesn't work. Below is my code, and I really hope that some can help me on this by pointing out what I did wrong. I greatly appreciate your help.
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Imports Scripting.FileSystemObjectClass
Imports System.IO.Path
Imports System.Runtime.InteropServices
Imports System.Text Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
----------------------------------------------------------------------------------------------------
Private Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
sbRemoteName As StringBuilder, ByRef cbRemoteName As Integer) As Integer
-----------------------------------------------------------------------------------------------------------
Public Function GetUNCFromMappedDrive(ByVal driveLetter As String) As String
Dim StrUNC As New StringBuilder(256)
If WNetGetConnection32(driveLetter, StrUNC, 256) > 0 Then
'Not a mapped drive
StrUNC.Append(driveLetter)
End If
Return String.Copy(StrUNC.ToString.TrimEnd)
End Function
---------------------------------------------------------------------------------------------------
'Getting filename, file path & current username
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofDlg As New OpenFileDialog
With ofDlg
'Filter for JPG files
.Filter = "Image Files (*.jpg)|*.jpg"
If .ShowDialog(Me) = DialogResult.OK Then
'Get filename
TextBox2.Text = IO.Path.GetFileName(.FileName)
'Get file path
TextBox3.Text = GetDirectoryName(.FileName)
End If
End With
'Get current username
TextBox1.Text = GetCurrent.Name
'Get the UNC path of the file
TextBox4.Text = GetUNCFromMappedDrive(TextBox3.Text.Substring(0, 3))
ofDlg.Dispose()
End Sub
End Class
Thank you, Dennis. You've saved my day.
The code you supplied works perfectly.
Thanks again.
Stanav.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com... Someone posted the below code on this newsgroup..it might work but I haven't tried it.
Public Declare Function WNetGetConnection Lib "mpr.dll" Alias _ "WNetGetConnectionA" (ByVal lpszLocalName As String, _ ByVal lpszRemoteName As String, ByRef cbRemoteName As Integer) As Integer
Sub Main() Dim ret As Integer Dim out As String = New String(" ", 260) Dim len As Integer = 260 ret = WNetGetConnection("Q:", out, len) Console.WriteLine(out) End Sub
-- Dennis in Houston
"Stanav" wrote:
Hello all, I'm trying to get the UNC path of a mapped network folder, but it somehow doesn't work. Below is my code, and I really hope that some can help me on this by pointing out what I did wrong. I greatly appreciate your help.
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Imports Scripting.FileSystemObjectClass
Imports System.IO.Path
Imports System.Runtime.InteropServices
Imports System.Text Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
----------------------------------------------------------------------------------------------------
Private Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
sbRemoteName As StringBuilder, ByRef cbRemoteName As Integer) As Integer
-----------------------------------------------------------------------------------------------------------
Public Function GetUNCFromMappedDrive(ByVal driveLetter As String) As String
Dim StrUNC As New StringBuilder(256)
If WNetGetConnection32(driveLetter, StrUNC, 256) > 0 Then
'Not a mapped drive
StrUNC.Append(driveLetter)
End If
Return String.Copy(StrUNC.ToString.TrimEnd)
End Function
---------------------------------------------------------------------------------------------------
'Getting filename, file path & current username
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofDlg As New OpenFileDialog
With ofDlg
'Filter for JPG files
.Filter = "Image Files (*.jpg)|*.jpg"
If .ShowDialog(Me) = DialogResult.OK Then
'Get filename
TextBox2.Text = IO.Path.GetFileName(.FileName)
'Get file path
TextBox3.Text = GetDirectoryName(.FileName)
End If
End With
'Get current username
TextBox1.Text = GetCurrent.Name
'Get the UNC path of the file
TextBox4.Text = GetUNCFromMappedDrive(TextBox3.Text.Substring(0, 3))
ofDlg.Dispose()
End Sub
End Class
Glad it worked. Need to thank the one who posted the code originally but I
didn't save his name.
--
Dennis in Houston
"Stanav" wrote: Thank you, Dennis. You've saved my day. The code you supplied works perfectly. Thanks again. Stanav.
"Dennis" <De****@discussions.microsoft.com> wrote in message news:A6**********************************@microsof t.com... Someone posted the below code on this newsgroup..it might work but I haven't tried it.
Public Declare Function WNetGetConnection Lib "mpr.dll" Alias _ "WNetGetConnectionA" (ByVal lpszLocalName As String, _ ByVal lpszRemoteName As String, ByRef cbRemoteName As Integer) As Integer
Sub Main() Dim ret As Integer Dim out As String = New String(" ", 260) Dim len As Integer = 260 ret = WNetGetConnection("Q:", out, len) Console.WriteLine(out) End Sub
-- Dennis in Houston
"Stanav" wrote:
Hello all, I'm trying to get the UNC path of a mapped network folder, but it somehow doesn't work. Below is my code, and I really hope that some can help me on this by pointing out what I did wrong. I greatly appreciate your help.
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Imports Scripting.FileSystemObjectClass
Imports System.IO.Path
Imports System.Runtime.InteropServices
Imports System.Text Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
----------------------------------------------------------------------------------------------------
Private Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
sbRemoteName As StringBuilder, ByRef cbRemoteName As Integer) As Integer
-----------------------------------------------------------------------------------------------------------
Public Function GetUNCFromMappedDrive(ByVal driveLetter As String) As String
Dim StrUNC As New StringBuilder(256)
If WNetGetConnection32(driveLetter, StrUNC, 256) > 0 Then
'Not a mapped drive
StrUNC.Append(driveLetter)
End If
Return String.Copy(StrUNC.ToString.TrimEnd)
End Function
---------------------------------------------------------------------------------------------------
'Getting filename, file path & current username
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofDlg As New OpenFileDialog
With ofDlg
'Filter for JPG files
.Filter = "Image Files (*.jpg)|*.jpg"
If .ShowDialog(Me) = DialogResult.OK Then
'Get filename
TextBox2.Text = IO.Path.GetFileName(.FileName)
'Get file path
TextBox3.Text = GetDirectoryName(.FileName)
End If
End With
'Get current username
TextBox1.Text = GetCurrent.Name
'Get the UNC path of the file
TextBox4.Text = GetUNCFromMappedDrive(TextBox3.Text.Substring(0, 3))
ofDlg.Dispose()
End Sub
End Class This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: farzad |
last post by:
Hi
I try to install php_ming.so in my php . I am using Redhat 8.0 php 4.2.2
apache 2.0.4.
I am doing as the howto install file want me to do.
as follow....
|
by: Adams-Blake Co. |
last post by:
This may be OT a bit, so maybe someone can point me in the right direction.
I want to test a script that sends out an e-mail. I want to test it locally
on my Mandrake Linux 8.2 box.
It runs OK...
|
by: lawrence |
last post by:
I haven't been able to reach www.php.net for days. Most of the rest of
the web is working for me, though I've bad trouble reaching any
English sites. Anyone else having trouble?
|
by: Michel |
last post by:
Hi,
I like to build a small simple dinamic website: Point-of-sale
(detail-shop), So entering stock, logging all sales, print out
invoices and download the logs to be imported into Excel.
I...
|
by: nadia |
last post by:
Is it possible to do the following in php:
I want to have a main form open. In the form I want a button that will
open a popup window so the user can search for something. The user can
then select...
| |
by: lawrence |
last post by:
How dangerous or stupid is it for an object to have a reference to the
object which contains it? If I have a class called $controllerForAll
which has an arrray of all the objects that exist, what...
|
by: Alper Adatoz |
last post by:
Hi,
i have a little problem. i hope u guys give me a clear solution (:
db: mssql
i just want to put jpeg file to the image field at the mssql db.
and after that i want to call it back..
|
by: Sam Hou |
last post by:
Dear all,
I don't know where my problem is. Hopefully someone can give me
some hint to explore the problem more. I am running Apache 2.0.48
wih PHP 4.3.4. The apache is running as nobody. I...
|
by: NotGiven |
last post by:
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.
How do you store a time variable?
How do you calculate...
|
by: Ryan Hubbard |
last post by:
I would like to limit multiple logins for a user. How and when does
the session id expire? Can I set it so after x minutes of inactivity
it would expire. How do I check if session id exists? If...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |