Write File to Network Drive using Wi Fi connection

R

Robert J

Hi,

I need to be able to write a text file and save it to a directory on a
Server
from in my Mobile Device program using VB.Net.

I can do this by calling a Web Service, but all the Servers on the sites
where my app is deployed can not, or will not, be running the .Net
framework.

What other options do I have FTP using sockets (almost sounded like,
I knew what I was talking about there) this would all be new to me, have
always used the winsock wrapper in VB 6 in the past.

Can you can access a network folder using the System.IO.Filestream by
\\Servername\C:\Folder ?

When I try to connect in this way from my Pocket Pc Device it always
asks for the Username and Passwords, is this related to permissions,
and can they be set for the mobile devices.

Still finding my way with .Net and the Compact Framework, so let me
know if I am barking up the wrong bush.

Cheers

Robert
 
P

Paul G. Tobey [eMVP]

You'll need to investigate quite a bit more thoroughly what will be
available on the server sides at all of your possible deployment locations
before we could suggest something that would work in all cases.

If every server would have FTP running on it, then you could, in theory, use
FTP to send the data file to the server. However, the FTP protocol is not a
lot of fun to implement yourself, so you would probably want to look at one
of the add-on products for .NET CF which would do that. You should be able
to search for FTP in the Google archives of this newsgroup to get some
suggestions.

http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework

If the server will be running a Web server in every case, that is another
possibility. The .NET CF's own support for HTTP:/HTML is closer to allowing
you to do this yourself, or, again, you could use the help of an add-on
product for file upload.

If the servers are all Windows-based, you might be able to map a shared
network 'drive' for use by the Windows CE device. I don't recall there
being any direct support in the Compact Framework for this, but I could be
wrong about that. Once the share was mapped, you could use the standard
file I/O stuff in .NET CF for the actual file operations (you simply create
the file in a particular location (something like \network\share name on
computername\desiredfilename).

Paul T.
 
R

Robert J

Thanks for the suggestions Paul.
The third option seems like it should be the easiest.
All Servers will be either running NT 4 Server or 2000 Server.

All the Servers are internal to the company I work for so I could easily
create the same Network share on them with read\write permission set
for Everyone.

The problem I have and I can't find any documentation on accessing that
share using the Compact Framework

If on each Server I created the share ReportsToPrint wouldn't this still
have to be
accessed using something like \\MyServer\ReportsToPrint\MyFile.txt ?

I have just tried to do something like that and using the following code:

Dim filename As String = "\\MyServer\ReportsToPrint\MyFiletxt"

Dim myFileStream As New System.IO.FileStream(filename, _
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Write, System.IO.FileShare.None)

' create a stream reader attach the file stream to it
Dim myWriter As New System.IO.StreamWriter(myFileStream)

As Soon as I go to open the FileStream the
Username:
Password:
Domain
pops up on the emulator, probably because the device isn't logged into the
Domain.

Is there any way around this ?

Cheers

Robert
 
J

jez

g'd day,

this is exactly what I'm using in my application. I "download" and "upload"
files using the copy() or move() method. It's actually extremely easy to use
and very fast (using WiFi!).

As for the username/password issue. I haven't found (didn't really look for
it) a solution for that. But you only need to enter the username/password
once and then save it. What I do here is that when I first set up the pocket
PC for the users I try to access a shared map. The Pocket PC then asks me
for a user/pass/domain, I fill it in and click on the save password
checkbox. Never got that dialog box again.

I supose that would kind of solve your problem.

jez
 
P

Paul G. Tobey [eMVP]

That is, if you set up the share manually before the first run of your
application, entering the password, etc. (or having the user do it), if
necessary, then you'd just assume that there is a folder \Network\sharename
on computername, and go from there. If that won't work for you, you'll have
to P/Invoke to the WNET routines (WNetAddConnection, etc.). There may have
been some traffic on doing this before, so check the newsgroup archives.

Paul T.

jez said:
g'd day,

this is exactly what I'm using in my application. I "download" and "upload"
files using the copy() or move() method. It's actually extremely easy to use
and very fast (using WiFi!).

As for the username/password issue. I haven't found (didn't really look for
it) a solution for that. But you only need to enter the username/password
once and then save it. What I do here is that when I first set up the pocket
PC for the users I try to access a shared map. The Pocket PC then asks me
for a user/pass/domain, I fill it in and click on the save password
checkbox. Never got that dialog box again.

I supose that would kind of solve your problem.

jez

Robert J said:
Thanks for the suggestions Paul.
The third option seems like it should be the easiest.
All Servers will be either running NT 4 Server or 2000 Server.

All the Servers are internal to the company I work for so I could easily
create the same Network share on them with read\write permission set
for Everyone.

The problem I have and I can't find any documentation on accessing that
share using the Compact Framework

If on each Server I created the share ReportsToPrint wouldn't this still
have to be
accessed using something like \\MyServer\ReportsToPrint\MyFile.txt ?

I have just tried to do something like that and using the following code:

Dim filename As String = "\\MyServer\ReportsToPrint\MyFiletxt"

Dim myFileStream As New System.IO.FileStream(filename, _
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Write, System.IO.FileShare.None)

' create a stream reader attach the file stream to it
Dim myWriter As New System.IO.StreamWriter(myFileStream)

As Soon as I go to open the FileStream the
Username:
Password:
Domain
pops up on the emulator, probably because the device isn't logged into the
Domain.

Is there any way around this ?

Cheers

Robert

theory,
use not at
one
http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework could
 
R

Robert J

Thanks mate, bit of a syntax error in your g'day though ;)

Might be going down another road now, was trying to find a way to
print Crystal Reports from my app, and writing a file to the Server
and having another app pick up the details and print the reports.

Now using xp_cmdshell to shell out to a program with command line arguments
that prints the reports, and it is working well so far.

Cheers

Robert

jez said:
g'd day,

this is exactly what I'm using in my application. I "download" and "upload"
files using the copy() or move() method. It's actually extremely easy to use
and very fast (using WiFi!).

As for the username/password issue. I haven't found (didn't really look for
it) a solution for that. But you only need to enter the username/password
once and then save it. What I do here is that when I first set up the pocket
PC for the users I try to access a shared map. The Pocket PC then asks me
for a user/pass/domain, I fill it in and click on the save password
checkbox. Never got that dialog box again.

I supose that would kind of solve your problem.

jez

Robert J said:
Thanks for the suggestions Paul.
The third option seems like it should be the easiest.
All Servers will be either running NT 4 Server or 2000 Server.

All the Servers are internal to the company I work for so I could easily
create the same Network share on them with read\write permission set
for Everyone.

The problem I have and I can't find any documentation on accessing that
share using the Compact Framework

If on each Server I created the share ReportsToPrint wouldn't this still
have to be
accessed using something like \\MyServer\ReportsToPrint\MyFile.txt ?

I have just tried to do something like that and using the following code:

Dim filename As String = "\\MyServer\ReportsToPrint\MyFiletxt"

Dim myFileStream As New System.IO.FileStream(filename, _
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Write, System.IO.FileShare.None)

' create a stream reader attach the file stream to it
Dim myWriter As New System.IO.StreamWriter(myFileStream)

As Soon as I go to open the FileStream the
Username:
Password:
Domain
pops up on the emulator, probably because the device isn't logged into the
Domain.

Is there any way around this ?

Cheers

Robert

theory,
use not at
one
http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework could
 
R

Robert J

I did a Google Search in this Newsgroup for WNetAddConnection but
only found this thread, where and how do I search in the archives ?

Going down a different path shelling out to another program on the server
using Stored Proc xp_cmdshell, but I am sure something like this will come
up
again.

I did found the declarations for the Functions and a Class to find existing
connections. I'm not familiar with P\Invoke have heard it mentioned though,
is it only used for the C family of languages ?

Well here is what I found in VB.Net for anyone interested.

Declare Function WNetAddConnection Lib "mpr.dll" Alias
"WNetAddConnectionA"(ByVal lpszNetPath As String, ByVal lpszPassword As
String, ByVal lpszLocalName As String) As Integer

Declare Function WNetAddConnection2 Lib "mpr.dll" Alias
"WNetAddConnection2A"(ByRef lpNetResource As NETRESOURCE, ByVal lpPassword
As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer

Public Class clsTestWNetGetConnection
#Region "Costanti"
Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_ABSENT = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
' returns errors for UNC Path
Private Const ERROR_BAD_DEVICE = 1200&
Private Const ERROR_CONNECTION_UNAVAIL = 1201&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NOT_SUPPORTED = 50&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const NO_ERROR = 0
#End Region
#Region "API"
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias
"GetLogicalDriveStringsA" (ByVal nBufferLength As Integer, ByVal lpBuffer As
String) As Integer
Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Integer
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As
String, ByRef cbRemoteName As Integer) As Integer
#End Region
#Region "Public Method"

Public function sListAllDrives() As String 'Show Drive Letter and Phisic
Path
Dim strAllDrives As String
Dim strTmp As String
Dim Ret As String

strAllDrives = fGetDrives()
If strAllDrives <> "" Then
Do
strTmp = Mid(strAllDrives, 1,
strAllDrives.IndexOf(vbNullChar) - 1)
strAllDrives = Mid(strAllDrives,
strAllDrives.IndexOf(vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media"
Ret &= "Removable drive : " & strTmp
Case "CD Rom"
Ret &= " CD Rom drive : " & strTmp
Case "Fixed Drive"
Ret &= " Local drive : " & strTmp
Case "Network Drive"
Ret &= " Network drive : " & strTmp
Ret &= " UNC Path : " &
fGetUNCPath(Left$(strTmp, Len(strTmp) - 1))
End Select
Loop While strAllDrives <> ""
End If
Return Ret
End Function

#End Region
#Region "Private Method"

Private Function fGetDrives() As String
'Returns all mapped drives
Dim lngRet As Integer
Dim strDrives As String = New String(Chr(32), 255)
Dim lngTmp As Integer
lngTmp = strDrives.Length
lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
fGetDrives = Left(strDrives, lngRet)
End Function

Private Function fGetUNCPath(ByVal strDriveLetter As String) As String

Try

Dim Msg As String
Dim lngReturn As Integer
Dim lpszLocalName As String
Dim lpszRemoteName As String
Dim cbRemoteName As Integer
lpszLocalName = strDriveLetter
lpszRemoteName = New String(Chr(32), 255)
cbRemoteName = lpszRemoteName.Length
lngReturn = WNetGetConnection(lpszLocalName, lpszRemoteName,
cbRemoteName)
Select Case lngReturn
Case ERROR_BAD_DEVICE
Msg = New String("Error: Bad Device")
Case ERROR_CONNECTION_UNAVAIL
Msg = New String("Error: Connection Un-Available")
Case ERROR_EXTENDED_ERROR
Msg = New String("Error: Extended Error")
Case ERROR_MORE_DATA
Msg = New String("Error: More Data")
Case ERROR_NOT_SUPPORTED
Msg = New String("Error: Feature not Supported")
Case ERROR_NO_NET_OR_BAD_PATH
Msg = New String("Error: No Network Available or Bad
Path")


Case ERROR_NO_NETWORK

Msg = New String("Error: No Network Available")
Case ERROR_NOT_CONNECTED
Msg = New String("Error: Not Connected")
Case NO_ERROR
' all is successful...
End Select
If Not (Msg Is Nothing) Then
MessageBox.Show(Msg, String.Empty, MessageBoxButtons.OK,
MessageBoxIcon.Information)
Return New String(String.Empty)
Else
fGetUNCPath = Left$(lpszRemoteName,
lpszRemoteName.IndexOf(Chr(0)))
End If
Catch Ex As Exception
MessageBox.Show(Ex.Message, String.Empty, MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Function

Private Function fDriveType(ByVal strDriveName As String) As String
Dim lngRet As Integer
Dim strDrive As String = New String(String.Empty)
lngRet = GetDriveType(strDriveName)
Select Case lngRet
Case DRIVE_UNKNOWN 'The drive type cannot be determined.
strDrive = New String("Unknown Drive Type")
Case DRIVE_ABSENT 'The root directory does not exist.
strDrive = New String("Drive does not exist")
Case DRIVE_REMOVABLE 'The drive can be removed from the drive.
strDrive = New String("Removable Media")
Case DRIVE_FIXED 'The disk cannot be removed from the drive.
strDrive = New String("Fixed Drive")
Case DRIVE_REMOTE 'The drive is a remote (network) drive.
strDrive = New String("Network Drive")
Case DRIVE_CDROM 'The drive is a CD-ROM drive.
strDrive = New String("CD Rom")
Case DRIVE_RAMDISK 'The drive is a RAM disk.
strDrive = New String("Ram Disk")
End Select
Return strDrive
End Function

#End Region
End Class

Cheers

Robert [VPDGOGYD]
 
J

jez

this is what happens when you haven't been down under for two years:p

I did hear/read a little bit about crystal reports but never really looked
thorougly into it because I wasn't planning on printing anything - plain
copying to the server (Navision does the import/export of the files). I
would however be interested, for future reference, about its
functionialities. Did you find any interesting/relevant info on a specific
website ?

jez
 
P

Paul G. Tobey [eMVP]

P/Invoke refers to "platform invoking" or calling into a non-managed API.
So, you can do it from any .NET language, although, obviously, the
declaration format for functions that you want to P/Invoke will be different
in each. When we say that you need to P/Invoke something, that simply means
that you have to call an API that is not directly supported by the managed
run-time. What you've got there looks like it will do what I was talking
about...

Paul T.

Robert J said:
I did a Google Search in this Newsgroup for WNetAddConnection but
only found this thread, where and how do I search in the archives ?

Going down a different path shelling out to another program on the server
using Stored Proc xp_cmdshell, but I am sure something like this will come
up
again.

I did found the declarations for the Functions and a Class to find existing
connections. I'm not familiar with P\Invoke have heard it mentioned though,
is it only used for the C family of languages ?

Well here is what I found in VB.Net for anyone interested.

Declare Function WNetAddConnection Lib "mpr.dll" Alias
"WNetAddConnectionA"(ByVal lpszNetPath As String, ByVal lpszPassword As
String, ByVal lpszLocalName As String) As Integer

Declare Function WNetAddConnection2 Lib "mpr.dll" Alias
"WNetAddConnection2A"(ByRef lpNetResource As NETRESOURCE, ByVal lpPassword
As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer

Public Class clsTestWNetGetConnection
#Region "Costanti"
Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_ABSENT = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
' returns errors for UNC Path
Private Const ERROR_BAD_DEVICE = 1200&
Private Const ERROR_CONNECTION_UNAVAIL = 1201&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NOT_SUPPORTED = 50&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const NO_ERROR = 0
#End Region
#Region "API"
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias
"GetLogicalDriveStringsA" (ByVal nBufferLength As Integer, ByVal lpBuffer As
String) As Integer
Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Integer
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As
String, ByRef cbRemoteName As Integer) As Integer
#End Region
#Region "Public Method"

Public function sListAllDrives() As String 'Show Drive Letter and Phisic
Path
Dim strAllDrives As String
Dim strTmp As String
Dim Ret As String

strAllDrives = fGetDrives()
If strAllDrives <> "" Then
Do
strTmp = Mid(strAllDrives, 1,
strAllDrives.IndexOf(vbNullChar) - 1)
strAllDrives = Mid(strAllDrives,
strAllDrives.IndexOf(vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media"
Ret &= "Removable drive : " & strTmp
Case "CD Rom"
Ret &= " CD Rom drive : " & strTmp
Case "Fixed Drive"
Ret &= " Local drive : " & strTmp
Case "Network Drive"
Ret &= " Network drive : " & strTmp
Ret &= " UNC Path : " &
fGetUNCPath(Left$(strTmp, Len(strTmp) - 1))
End Select
Loop While strAllDrives <> ""
End If
Return Ret
End Function

#End Region
#Region "Private Method"

Private Function fGetDrives() As String
'Returns all mapped drives
Dim lngRet As Integer
Dim strDrives As String = New String(Chr(32), 255)
Dim lngTmp As Integer
lngTmp = strDrives.Length
lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
fGetDrives = Left(strDrives, lngRet)
End Function

Private Function fGetUNCPath(ByVal strDriveLetter As String) As String

Try

Dim Msg As String
Dim lngReturn As Integer
Dim lpszLocalName As String
Dim lpszRemoteName As String
Dim cbRemoteName As Integer
lpszLocalName = strDriveLetter
lpszRemoteName = New String(Chr(32), 255)
cbRemoteName = lpszRemoteName.Length
lngReturn = WNetGetConnection(lpszLocalName, lpszRemoteName,
cbRemoteName)
Select Case lngReturn
Case ERROR_BAD_DEVICE
Msg = New String("Error: Bad Device")
Case ERROR_CONNECTION_UNAVAIL
Msg = New String("Error: Connection Un-Available")
Case ERROR_EXTENDED_ERROR
Msg = New String("Error: Extended Error")
Case ERROR_MORE_DATA
Msg = New String("Error: More Data")
Case ERROR_NOT_SUPPORTED
Msg = New String("Error: Feature not Supported")
Case ERROR_NO_NET_OR_BAD_PATH
Msg = New String("Error: No Network Available or Bad
Path")


Case ERROR_NO_NETWORK

Msg = New String("Error: No Network Available")
Case ERROR_NOT_CONNECTED
Msg = New String("Error: Not Connected")
Case NO_ERROR
' all is successful...
End Select
If Not (Msg Is Nothing) Then
MessageBox.Show(Msg, String.Empty, MessageBoxButtons.OK,
MessageBoxIcon.Information)
Return New String(String.Empty)
Else
fGetUNCPath = Left$(lpszRemoteName,
lpszRemoteName.IndexOf(Chr(0)))
End If
Catch Ex As Exception
MessageBox.Show(Ex.Message, String.Empty, MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Function

Private Function fDriveType(ByVal strDriveName As String) As String
Dim lngRet As Integer
Dim strDrive As String = New String(String.Empty)
lngRet = GetDriveType(strDriveName)
Select Case lngRet
Case DRIVE_UNKNOWN 'The drive type cannot be determined.
strDrive = New String("Unknown Drive Type")
Case DRIVE_ABSENT 'The root directory does not exist.
strDrive = New String("Drive does not exist")
Case DRIVE_REMOVABLE 'The drive can be removed from the drive.
strDrive = New String("Removable Media")
Case DRIVE_FIXED 'The disk cannot be removed from the drive.
strDrive = New String("Fixed Drive")
Case DRIVE_REMOTE 'The drive is a remote (network) drive.
strDrive = New String("Network Drive")
Case DRIVE_CDROM 'The drive is a CD-ROM drive.
strDrive = New String("CD Rom")
Case DRIVE_RAMDISK 'The drive is a RAM disk.
strDrive = New String("Ram Disk")
End Select
Return strDrive
End Function

#End Region
End Class

Cheers

Robert [VPDGOGYD]

Paul G. Tobey said:
That is, if you set up the share manually before the first run of your
application, entering the password, etc. (or having the user do it), if
necessary, then you'd just assume that there is a folder \Network\sharename
on computername, and go from there. If that won't work for you, you'll have
to P/Invoke to the WNET routines (WNetAddConnection, etc.). There may have
been some traffic on doing this before, so check the newsgroup archives.

Paul T.

to
use look
for into
the
protocol
is look
at
should
http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework
directory
on System.IO.Filestream
by
 
R

Robert J

Thanks Paul I dug a little deeper and found a message that pointed to a nice
example

http://msdn.microsoft.com/mobility/...ary/en-us/dnnetcomp/html/netcfintrointerp.asp

I managed to get my unmanaged brain around it.

Robert

Paul G. Tobey said:
P/Invoke refers to "platform invoking" or calling into a non-managed API.
So, you can do it from any .NET language, although, obviously, the
declaration format for functions that you want to P/Invoke will be different
in each. When we say that you need to P/Invoke something, that simply means
that you have to call an API that is not directly supported by the managed
run-time. What you've got there looks like it will do what I was talking
about...

Paul T.

Robert J said:
I did a Google Search in this Newsgroup for WNetAddConnection but
only found this thread, where and how do I search in the archives ?

Going down a different path shelling out to another program on the server
using Stored Proc xp_cmdshell, but I am sure something like this will come
up
again.

I did found the declarations for the Functions and a Class to find existing
connections. I'm not familiar with P\Invoke have heard it mentioned though,
is it only used for the C family of languages ?

Well here is what I found in VB.Net for anyone interested.

Declare Function WNetAddConnection Lib "mpr.dll" Alias
"WNetAddConnectionA"(ByVal lpszNetPath As String, ByVal lpszPassword As
String, ByVal lpszLocalName As String) As Integer

Declare Function WNetAddConnection2 Lib "mpr.dll" Alias
"WNetAddConnection2A"(ByRef lpNetResource As NETRESOURCE, ByVal lpPassword
As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer

Public Class clsTestWNetGetConnection
#Region "Costanti"
Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_ABSENT = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
' returns errors for UNC Path
Private Const ERROR_BAD_DEVICE = 1200&
Private Const ERROR_CONNECTION_UNAVAIL = 1201&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NOT_SUPPORTED = 50&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const NO_ERROR = 0
#End Region
#Region "API"
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias
"GetLogicalDriveStringsA" (ByVal nBufferLength As Integer, ByVal
lpBuffer
As
String) As Integer
Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Integer
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal
lpszRemoteName
As
String, ByRef cbRemoteName As Integer) As Integer
#End Region
#Region "Public Method"

Public function sListAllDrives() As String 'Show Drive Letter and Phisic
Path
Dim strAllDrives As String
Dim strTmp As String
Dim Ret As String

strAllDrives = fGetDrives()
If strAllDrives <> "" Then
Do
strTmp = Mid(strAllDrives, 1,
strAllDrives.IndexOf(vbNullChar) - 1)
strAllDrives = Mid(strAllDrives,
strAllDrives.IndexOf(vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media"
Ret &= "Removable drive : " & strTmp
Case "CD Rom"
Ret &= " CD Rom drive : " & strTmp
Case "Fixed Drive"
Ret &= " Local drive : " & strTmp
Case "Network Drive"
Ret &= " Network drive : " & strTmp
Ret &= " UNC Path : " &
fGetUNCPath(Left$(strTmp, Len(strTmp) - 1))
End Select
Loop While strAllDrives <> ""
End If
Return Ret
End Function

#End Region
#Region "Private Method"

Private Function fGetDrives() As String
'Returns all mapped drives
Dim lngRet As Integer
Dim strDrives As String = New String(Chr(32), 255)
Dim lngTmp As Integer
lngTmp = strDrives.Length
lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
fGetDrives = Left(strDrives, lngRet)
End Function

Private Function fGetUNCPath(ByVal strDriveLetter As String) As String

Try

Dim Msg As String
Dim lngReturn As Integer
Dim lpszLocalName As String
Dim lpszRemoteName As String
Dim cbRemoteName As Integer
lpszLocalName = strDriveLetter
lpszRemoteName = New String(Chr(32), 255)
cbRemoteName = lpszRemoteName.Length
lngReturn = WNetGetConnection(lpszLocalName, lpszRemoteName,
cbRemoteName)
Select Case lngReturn
Case ERROR_BAD_DEVICE
Msg = New String("Error: Bad Device")
Case ERROR_CONNECTION_UNAVAIL
Msg = New String("Error: Connection Un-Available")
Case ERROR_EXTENDED_ERROR
Msg = New String("Error: Extended Error")
Case ERROR_MORE_DATA
Msg = New String("Error: More Data")
Case ERROR_NOT_SUPPORTED
Msg = New String("Error: Feature not Supported")
Case ERROR_NO_NET_OR_BAD_PATH
Msg = New String("Error: No Network Available or Bad
Path")


Case ERROR_NO_NETWORK

Msg = New String("Error: No Network Available")
Case ERROR_NOT_CONNECTED
Msg = New String("Error: Not Connected")
Case NO_ERROR
' all is successful...
End Select
If Not (Msg Is Nothing) Then
MessageBox.Show(Msg, String.Empty, MessageBoxButtons.OK,
MessageBoxIcon.Information)
Return New String(String.Empty)
Else
fGetUNCPath = Left$(lpszRemoteName,
lpszRemoteName.IndexOf(Chr(0)))
End If
Catch Ex As Exception
MessageBox.Show(Ex.Message, String.Empty, MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Function

Private Function fDriveType(ByVal strDriveName As String) As String
Dim lngRet As Integer
Dim strDrive As String = New String(String.Empty)
lngRet = GetDriveType(strDriveName)
Select Case lngRet
Case DRIVE_UNKNOWN 'The drive type cannot be determined.
strDrive = New String("Unknown Drive Type")
Case DRIVE_ABSENT 'The root directory does not exist.
strDrive = New String("Drive does not exist")
Case DRIVE_REMOVABLE 'The drive can be removed from the drive.
strDrive = New String("Removable Media")
Case DRIVE_FIXED 'The disk cannot be removed from the drive.
strDrive = New String("Fixed Drive")
Case DRIVE_REMOTE 'The drive is a remote (network) drive.
strDrive = New String("Network Drive")
Case DRIVE_CDROM 'The drive is a CD-ROM drive.
strDrive = New String("CD Rom")
Case DRIVE_RAMDISK 'The drive is a RAM disk.
strDrive = New String("Ram Disk")
End Select
Return strDrive
End Function

#End Region
End Class

Cheers

Robert [VPDGOGYD]

Paul G. Tobey said:
That is, if you set up the share manually before the first run of your
application, entering the password, etc. (or having the user do it), if
necessary, then you'd just assume that there is a folder \Network\sharename
on computername, and go from there. If that won't work for you,
you'll
have
to P/Invoke to the WNET routines (WNetAddConnection, etc.). There may have
been some traffic on doing this before, so check the newsgroup archives.

Paul T.

g'd day,

this is exactly what I'm using in my application. I "download" and
"upload"
files using the copy() or move() method. It's actually extremely
easy
to
use
and very fast (using WiFi!).

As for the username/password issue. I haven't found (didn't really look
for
it) a solution for that. But you only need to enter the username/password
once and then save it. What I do here is that when I first set up the
pocket
PC for the users I try to access a shared map. The Pocket PC then
asks
me
for a user/pass/domain, I fill it in and click on the save password
checkbox. Never got that dialog box again.

I supose that would kind of solve your problem.

jez

Thanks for the suggestions Paul.
The third option seems like it should be the easiest.
All Servers will be either running NT 4 Server or 2000 Server.

All the Servers are internal to the company I work for so I could easily
create the same Network share on them with read\write permission set
for Everyone.

The problem I have and I can't find any documentation on accessing that
share using the Compact Framework

If on each Server I created the share ReportsToPrint wouldn't this still
have to be
accessed using something like \\MyServer\ReportsToPrint\MyFile.txt ?

I have just tried to do something like that and using the following
code:

Dim filename As String = "\\MyServer\ReportsToPrint\MyFiletxt"

Dim myFileStream As New System.IO.FileStream(filename, _
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Write, System.IO.FileShare.None)

' create a stream reader attach the file stream to it
Dim myWriter As New System.IO.StreamWriter(myFileStream)

As Soon as I go to open the FileStream the
Username:
Password:
Domain
pops up on the emulator, probably because the device isn't logged into
the
Domain.

Is there any way around this ?

Cheers

Robert

"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com>
wrote
in
message You'll need to investigate quite a bit more thoroughly what will be
available on the server sides at all of your possible deployment
locations
before we could suggest something that would work in all cases.

If every server would have FTP running on it, then you could, in
theory,
use
FTP to send the data file to the server. However, the FTP
protocol
is
not
a
lot of fun to implement yourself, so you would probably want to look
at
one
of the add-on products for .NET CF which would do that. You
should
be
able
to search for FTP in the Google archives of this newsgroup to
get
some
suggestions.
http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework
directory to
me, let
me
 
R

Robert J

Only that you can't use it from the Compact Framework, but the release notes
for version 10 mention something about Pocket PC.

I also tried using it in a web service that was passed the file name,
printer and parameters
with no joy. Our company has historically always used Crystal but I have
read there
are better programs out there and some that do work on pocket pc.

Crystal is a hefty beast so they would really have to trim it down to work
under the CF.

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top