如何从文件路径获取文件名并使用datalist显示文件名。 [英] How to get file name from file path and display file name using datalist.

查看:154
本文介绍了如何从文件路径获取文件名并使用datalist显示文件名。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在datalist中绑定用户的详细信息。在datalist中我想绑定由用户上传的文档完整路径的文件名。在数据库中,我将文档的完整路径存储在FolderName列中。在FolderName列中,我存储文档的完整路径。我使用视图绑定datalist。



I am binding details of user in datalist .In datalist i want to bind File Name insted of Full Path of Document which is uploaded by user.In Database i store the Full Path of document in column FolderName. In FolderName column i store the full path of document. I am binding datalist using view.

<asp:DataList runat="server" ID="dlContacts" Width="100%"

                BorderStyle="Groove" >
                <HeaderTemplate>
                    <table width="100%">
                        <tr>
                            <td>
                                OrganisationName
                            </td>
                            <td>
                                Details
                            </td>
                            <td>
                            File Name
                            </td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <%#Eval("OrganisationName")%>
                        </td>
                        <td>
                            <%#Eval("OrganisationDetails")%>
                        </td>
                        <td>
                         (<%# Eval(System.IO.Path.GetFileName("FolderName")%>)
                        </td>
                        <td style="text-align: right;">
                            <asp:Button ID="btnEdit" Text="Edit" runat="server" CommandName="edit" />
                        </td>
                        <td style="text-align: right;">
                            <asp:Button ID="btnDelete" Text="Delete" runat="server" CommandName="delete" />
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table></FooterTemplate>
            </asp:DataList>

推荐答案

试试这个...根据您的变量进行调整。



string Filename = CompletePath.S ubstring(CompletePath.LastIndexOf(\\)+ 1);





现在,如果您的数据存储在数据表,要么修改数据表,添加列,并在绑定到列表之前用提取的文件名填充该列,要么处理绑定的rowdatabound事件以处理文件名的提取。
try this... just make an adjustment based on your variables.

string Filename = CompletePath.Substring(CompletePath.LastIndexOf("\\") + 1);


now, if your data is stored in a datatable, either you modify the datatable, add a column, and fill that column with the extracted filename before binding to a list, or handle the binding''s rowdatabound event to handle the extraction of filename.


这篇关于如何从文件路径获取文件名并使用datalist显示文件名。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆