Hallo,
I need to write an ASPX.
VB application, that would allow me to crate a database of documents, that are stored on a local net. Therefore I need to convert local file names (with mapped drives) into UNC name. I am able to convert it on a local machine (as shown below), but when I put this application on a server, it wants to run the code on a server side and fails.
Do you have any idea how to force the application to convert the name into UNC name on local side and only then pass it to server ?
DAFEULT.ASPX
<%@ Page Language="
VB" AutoEventWireup="false" CodeFile="Default.aspx.
vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta content="text/VBScript" http-equiv="content-script-type" />
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" usesubmitbehavior="true" runat="server" Text="Button" OnClick="Button1_Click" /><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br />
</div>
</form>
</body>
</html>
DEFAULT.ASPX.
VB
Partial Class _Default
Inherits System.Web.UI.Page
Dim XXX As String
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName _
As String, ByVal UNC As System.Text.StringBuilder, _
ByRef cbRemoteName As Integer) As Integer
Private Function GetUNCNameNT(ByVal pathName As String) As String
Dim ErrCode As Integer
Dim Length As Integer = 255
Dim UNC As New System.Text.StringBuilder(Length)
ErrCode = WNetGetConnection(pathName, UNC, Length)
GetUNCNameNT = UNC.ToString
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "-- " + GetUNCNameNT("U:") + " --"
End Sub
End Class