473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

List files in a directory, modify name.

Hi,

I have made a code that list all files in a directory on the server.
It works fine, but I need to modify the filename (remove the 7 first char in
the name) that is displayed in the datagrid.

Example:
The file "123456_myfile.jpg" shoult be displayed like this: "myfile.jpg"

---------------------------
This is my code so far:
---------------------------

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dirInfo As New
DirectoryInfo(Server.MapPath("/uploads/isaksenmedia/"))
Me.dtgFilelist.DataSource = dirInfo.GetFiles("*.*")
Me.dtgFilelist.DataBind()
End Sub
<asp:DataGrid id="dtgFilelist" runat="server" autogeneratecolumns="False">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="Filename" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Modyfied"
DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="Size"
DataFormatString="{0:#,### bytes}" />
</Columns>
</asp:DataGrid>

Thanks!!!!!!
Feb 10 '06 #1
3 1322
If i were you, I would dump the GetFiles into a collection first and
iterate through that, changing the names while it is still in a
collection, then bind this collection to the datagrid, it would be
easier then binding it to the datagrid and then changing it.

Feb 10 '06 #2
Ok, I sounds like a smart way to do it!
Could you please help me get started making this "collection", I'm not shure
how to do this... Guess this is an array...?

Thanks alot!!!

"DKode" <dk****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
If i were you, I would dump the GetFiles into a collection first and
iterate through that, changing the names while it is still in a
collection, then bind this collection to the datagrid, it would be
easier then binding it to the datagrid and then changing it.

Feb 10 '06 #3
ok,

GetFiles returns a FileInfo[] collection

if you go to msdn.microsoft.com and look up FileInfo class, you'll see
all the different properties you can get about a file, it depends on
what you want out of FileInfo class. you can setup a foreach and
iterate through the FileInfo[] collection changing properties if you
want:

i havent tested this code, but you should point you in the right
direction

FileInfo[] files = dirInfo.GetFiles();

foreach (FileInfo f in files) {
f.Name = f.Name.substring(8, f.Name.Length - 8);
}

DataGrid myDataGrid.DataSource = files;
myDataGrid.DataBind();

that substring might throw an error because of the length of the
substring, but you get the idea.

hope this helps

Feb 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken | last post by:
I currently have a set of documents in a directory that i need to list in a html table. Is there any way to generate the table with the documents listed instead of having to update the table...
3
by: mallyonline | last post by:
Thank you for your previous help. I posted regarding listing the names of files held in a folder on the server and making the list appear clickable. This has now been accomplished. The...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
11
by: Madison Kelly | last post by:
Hi all, I am new to the list and I didn't want to seem rude at all so I wanted to ask if this was okay first. I have a program I have written in perl which uses a postgresSQL database as the...
4
by: thoseion | last post by:
Hi, I am trying to get a program working whereby directory and file names are read into a list. I have been given the original list structure - it appears that the directory names should be added...
3
by: rn5a | last post by:
I am not very sure whether I should have continued with my earlier thread or started a new thread whose subject matter was somewhat similar to the subject matter in this thread. Anyway after much...
0
by: Henning Krause [MVP - Exchange] | last post by:
Hello, Environment: Visual Studio 2005 SP1, Web Deployment Projects installed I hava Web Application project (updated from Visual Studio 2003) and a Web Deployment for that web application....
3
by: Killer42 | last post by:
Here's a simple VB6 code snippet that uses the FileSystemObject model to find all the files in C:\Temp and load their names into a listbox. To use this sample, you need to set things up as follows: ...
6
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.