Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2007, 08:44 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Convert FileName into UNC name on local

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


 
Old August 6th, 2007, 10:15 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Most likely the problem here is that the server doesn't have the mapped drives. To my knowledge and experience, it's difficult or least unreliable to have mapped drives on a server outside of a user login context.

Can you explain a little more about what your application is going to do? There might be a better way to do it.

Where are the files coming from and going to?

-Peter
 
Old August 7th, 2007, 01:23 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 Most likely the problem here is that the server doesn't have the mapped drives. To my knowledge and experience, it's difficult or least unreliable to have mapped drives on a server outside of a user login context.

Can you explain a little more about what your application is going to do? There might be a better way to do it.

Where are the files coming from and going to?

-Peter
Well. There's more than ten servers and several hundreds of PCs in our network. Users share their documents (DOC,XLS,PDF,PPS ...) on servers, but the more documents there are, the harder is to find anything. I should make a database for searching in these documents (without necessity to install any .exe to the users). Problem is, that file on my computer "U:\AnyDocument.DOC" is stored at "\\server1\\ISO Documents\AnyDocument.DOC" and somebody else sees it as "K:\ISO Documents\AnyDocument.DOC".
Users are supposed to add documents into database yourselves. And if I add "U: ....", it has to be stored in the SQL database as "\\server1 ..." to ensure that the other users wil be able to access it.
So what I need is : aspx application on a server has a function "Add a new document". User pick some file from their local mapped drive, but the application stores into database general UNC name of picked document.

 
Old August 7th, 2007, 08:47 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think this is going to be very difficult to do with a simple ASP.NET app. If you pick a path to a document and provide that to the server, the app at the server is not going to know that you are using a drive mapping (\\server1 == U:) versus actually having a physical drive that uses the U: drive letter. I see 2 options at this point:

1) The app keeps a list of all the possible document locations and drops the drive letter from the posted path, then looks thru all the possible locations for a file matching the path. Not terribly efficient but it would probably work.

2) Save user mappings within the app (could use some persistant store [db, xml file, etc.] or cookies, something like that). When the user posts a path to store, change the user's local path reference into the UNC by swapping out their local mappings with the server paths. One user's K: is another users U: but they both map to \\server1 so you can resolve the UNC path.

If you were doing this with a windows app I would venture a guess that there is some capability of resolving a file path to the real physical location. I could imagine that the .NET framework may not directly be able to determine that "U:\somefile" maps to "\\server1\somefile" but it's likely you could import an external windows API call that could do that. But again, this only helps if you're do a local app, no good for ASP.NET.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
UNC Network Path stonesbg ASP.NET 2.0 Basics 1 February 1st, 2007 11:28 AM
Filesystemobject and UNC paths dlfisher1972 Pro VB 6 0 January 5th, 2006 01:44 PM
Using UNC in data source rguidry Classic ASP Databases 2 March 29th, 2005 10:02 AM
Get UNC for a local file Mitch Access 0 August 12th, 2003 02:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.