DataNavigateUrlField lists URL from ADMIN dir instead of NewDir RRS feed

  • Question

  • User587445502 posted


     I'm struggling with the following challenge:

     I'm using a clubstarterskit and want to add/delete documents from a (manage.)page in the admin directory. This directory is, as you probably know, only used for special login accounts (i.e. administrators).

    Standard users, with no administrators-account, can view a (document)page which lists the available documents in this directory. If you want to add or delete a document i use a manage.page in the admin directory. But when i list the available documents in this page it shows the *.docs in the admin directory instead of the default home-directory.

    Below some code I'm using for this:

    If Not Page.IsPostBack Then
                Dim dirInfo As DirectoryInfo = New DirectoryInfo("c:\Websites\SQL\")
                ArticleList.DataSource = dirInfo.GetFiles("*.doc")
            End If
      End Sub

    and this is the code that listens the doc's

    <asp:DataGrid runat="server" id="ArticleList"
          AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
          HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
          HeaderStyle-Font-Size="10pt" HeaderStyle-Font-Bold="True"
        <asp:ButtonColumn Text="Delete" ButtonType="PushButton"
                  CommandName="Delete" />
          <asp:HyperLinkColumn DataNavigateUrlField="Name"   DataTextField="Name" HeaderText="File Name" />
          <asp:BoundColumn DataField="LastWriteTime"
                  HeaderText="Last Write Time"
                  DataFormatString="{0:d}" />


    What's not clear to me is that this code lists the documents from C:\WEBSITES\SQL but when i use the hyperlink to open the document,  i'm getting an error whichs states that there is no such document in de directory C:\WEBSITES\SQL\ADMIN

    So it looks to me that  <asp:HyperLinkColumn DataNavigateUrlField="Name"   DataTextField="Name" HeaderText="File Name" /> is the code that points to ...\ADMIN

    My question is: how can i change this code to point to the right directory as stated in: Dim dirInfo As DirectoryInfo = New DirectoryInfo("c:\Websites\SQL\") ?




    Sunday, August 19, 2007 4:14 PM

All replies

  • User-2041767123 posted

    Change your markup like this:

    <asp:HyperLinkColumn DataNavigateUrlField='<%# FormatDocName(Eval("Name")  %>'  DataTextField="Name" HeaderText="File Name" />

    Then you should make a protected function in your code-behind which returns a string. In this function you can return a string with the right path and the filename you get as a parameter in this function. Since the field Name doesn't contain a path, it will open in your current directory which is Admin at that time.

    Sunday, August 19, 2007 5:25 PM
  • User437720957 posted

    It's not strange at all. The hyperlinks will receive their NavigateUrl from the Name property of the FileInfo:s. If you have a file called "testfile.txt" in the directory, you will get a hyperlink with href="testfile.txt", in other words, a relative link. In this case it's relative to the adnin directory. Basically you will have to use a TemplateField instead of a HyperlinkField, where you can manipulate the NavigateUrl.




    Sunday, August 19, 2007 5:54 PM
  • User587445502 posted

    Unfortunately I do not have the skills to write such a piece of code in VB. Can you provide me with an example ?

    Monday, August 20, 2007 7:30 AM