File list to DataGrid

T

tshad

I am getting a list of files from a folder in my website and it displays
fine.

But it is not putting the actual path into the file column.

My code is:

DirectoryInfo dirInfo = new
DirectoryInfo(Server.MapPath("/integration/ImportFile/"));
articleList.DataSource = dirInfo.GetFiles("*.txt");
articleList.DataBind();

It shows the correct files, but if I select the filename to display it - it
can't find it.

What I get is:

http://localhost/integration/EmployeeExtras.txt

It should be:

http://localhost/inetpub/wwwroot/integration/EmployeeExtras.txt

What am I doing wrong here? Doesn't MapPath work correctly? It does get
the correct files - just not the correct paths.

Thanks,

Tom
 
T

tshad

tshad said:
I am getting a list of files from a folder in my website and it displays
fine.

But it is not putting the actual path into the file column.

My code is:

DirectoryInfo dirInfo = new
DirectoryInfo(Server.MapPath("/integration/ImportFile/"));
articleList.DataSource = dirInfo.GetFiles("*.txt");
articleList.DataBind();

It shows the correct files, but if I select the filename to display it -
it can't find it.

What I get is:

http://localhost/integration/EmployeeExtras.txt

It should be:

http://localhost/inetpub/wwwroot/integration/EmployeeExtras.txt

In my Delete routine from the ItemDataBound event I can do this:

string fileName = (string)articleList.DataKeys[e.Item.ItemIndex];

This gives me the correct path as shown above.

But the first column (HyperLink column) does not get the correct path.

The DataGrid looks like:

<asp:datagrid id="articleList" runat="server" HeaderStyle-Font-Bold="True"
HeaderStyle-Font-Size="15pt"
HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Navy"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False" Font-Name="Verdana" DataKeyField="FullName"
OnItemDataBound="articleList_ItemDataBound"
OnDeleteCommand="articleList_DeleteFile">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time"
ItemStyle-HorizontalAlign="Center"
DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="File Size"
ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,##0 bytes}" />
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
CommandName="Delete" />
</Columns>
</asp:datagrid>

Thanks,

Tom
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top