473,326 Members | 2,048 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,326 software developers and data experts.

Files too DataGrid Help Plz

Hi everyone,

In C#, is there a easy way of display files (ie. mp3 files) to a datagrid?
If someone can provide me with some code, or advice I would appreciated it.

Thanks in advance.

MikeY
Nov 17 '05 #1
4 1499
MikeY,

What do you mean to a datagrid? A datagrid is for tabular data, whereas
an MP3 is an audio file. They are incompatable.

Or do you mean a file listing? In this case, you should be able to use
the Directory object, setting the data source to the return value from the
static GetFiles method (since it returns an array of strings).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MikeY" <mi*******@yaho.com> wrote in message
news:RH*******************@news20.bellglobal.com.. .
Hi everyone,

In C#, is there a easy way of display files (ie. mp3 files) to a datagrid?
If someone can provide me with some code, or advice I would appreciated
it.

Thanks in advance.

MikeY

Nov 17 '05 #2
Hi Ncholas,

Thanks for replying. I'm trying to display my mp3 files that reside in a
folder, then display all mp3 files within that folder in a datagrid. below
is a sample of my code, but it is just displaying the last file and not all
of them.

private Item[] items = new Item[]{};

protected class Item
{
public Item(string text)
{
m_text = text;
}
public string Text
{
get
{
return m_text;
}
}
private string m_text;
}
private void btnRetrieve_Click(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\Documents
and Settings\MikeYAdmin\Desktop\Music 1");

DirectoryInfo[] myDirectory = dir.GetDirectories();
FileInfo[] myInfo = dir.GetFiles();

foreach(System.IO.FileInfo fi in myInfo)
{
items = new Item[]{new Item(fi.Name)};
}

this.dGridTest.SetDataBinding(items, null);
}

MikeY

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eu**************@TK2MSFTNGP10.phx.gbl...
MikeY,

What do you mean to a datagrid? A datagrid is for tabular data,
whereas an MP3 is an audio file. They are incompatable.

Or do you mean a file listing? In this case, you should be able to use
the Directory object, setting the data source to the return value from the
static GetFiles method (since it returns an array of strings).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MikeY" <mi*******@yaho.com> wrote in message
news:RH*******************@news20.bellglobal.com.. .
Hi everyone,

In C#, is there a easy way of display files (ie. mp3 files) to a
datagrid? If someone can provide me with some code, or advice I would
appreciated it.

Thanks in advance.

MikeY


Nov 17 '05 #3
the problem is here

foreach(System.IO.FileInfo fi in myInfo)
{
items = new Item[]{new Item(fi.Name)}; //only the last FileInfo is
preserved
}

this is what you need to do:

items = new Item[myInfo.Length];
int i = 0;
foreach(System.IO.FileInfo fi in myInfo)
{
items[i] = new Item(fi.Name);
i++;
}

"MikeY" <mi*******@yaho.com> wrote in message
news:0m*******************@news20.bellglobal.com.. .
Hi Ncholas,

Thanks for replying. I'm trying to display my mp3 files that reside in a
folder, then display all mp3 files within that folder in a datagrid. below
is a sample of my code, but it is just displaying the last file and not all of them.

private Item[] items = new Item[]{};

protected class Item
{
public Item(string text)
{
m_text = text;
}
public string Text
{
get
{
return m_text;
}
}
private string m_text;
}
private void btnRetrieve_Click(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\Documents
and Settings\MikeYAdmin\Desktop\Music 1");

DirectoryInfo[] myDirectory = dir.GetDirectories();
FileInfo[] myInfo = dir.GetFiles();

foreach(System.IO.FileInfo fi in myInfo)
{
items = new Item[]{new Item(fi.Name)};
}

this.dGridTest.SetDataBinding(items, null);
}

MikeY

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eu**************@TK2MSFTNGP10.phx.gbl...
MikeY,

What do you mean to a datagrid? A datagrid is for tabular data,
whereas an MP3 is an audio file. They are incompatable.

Or do you mean a file listing? In this case, you should be able to use the Directory object, setting the data source to the return value from the static GetFiles method (since it returns an array of strings).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MikeY" <mi*******@yaho.com> wrote in message
news:RH*******************@news20.bellglobal.com.. .
Hi everyone,

In C#, is there a easy way of display files (ie. mp3 files) to a
datagrid? If someone can provide me with some code, or advice I would
appreciated it.

Thanks in advance.

MikeY



Nov 17 '05 #4
Thank you very much Lebesgue,

This is exactly what I was looking for and solved my problem.

Txs again
MikeY
"Lebesgue" <no****@spam.jp> wrote in message
news:uj*************@TK2MSFTNGP11.phx.gbl...
the problem is here

foreach(System.IO.FileInfo fi in myInfo)
{
items = new Item[]{new Item(fi.Name)}; //only the last FileInfo is
preserved
}

this is what you need to do:

items = new Item[myInfo.Length];
int i = 0;
foreach(System.IO.FileInfo fi in myInfo)
{
items[i] = new Item(fi.Name);
i++;
}

"MikeY" <mi*******@yaho.com> wrote in message
news:0m*******************@news20.bellglobal.com.. .
Hi Ncholas,

Thanks for replying. I'm trying to display my mp3 files that reside in a
folder, then display all mp3 files within that folder in a datagrid.
below
is a sample of my code, but it is just displaying the last file and not

all
of them.

private Item[] items = new Item[]{};

protected class Item
{
public Item(string text)
{
m_text = text;
}
public string Text
{
get
{
return m_text;
}
}
private string m_text;
}
private void btnRetrieve_Click(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\Documents
and Settings\MikeYAdmin\Desktop\Music 1");

DirectoryInfo[] myDirectory = dir.GetDirectories();
FileInfo[] myInfo = dir.GetFiles();

foreach(System.IO.FileInfo fi in myInfo)
{
items = new Item[]{new Item(fi.Name)};
}

this.dGridTest.SetDataBinding(items, null);
}

MikeY

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote

in
message news:eu**************@TK2MSFTNGP10.phx.gbl...
> MikeY,
>
> What do you mean to a datagrid? A datagrid is for tabular data,
> whereas an MP3 is an audio file. They are incompatable.
>
> Or do you mean a file listing? In this case, you should be able to use > the Directory object, setting the data source to the return value from the > static GetFiles method (since it returns an array of strings).
>
> Hope this helps.
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
> "MikeY" <mi*******@yaho.com> wrote in message
> news:RH*******************@news20.bellglobal.com.. .
>> Hi everyone,
>>
>> In C#, is there a easy way of display files (ie. mp3 files) to a
>> datagrid? If someone can provide me with some code, or advice I would
>> appreciated it.
>>
>> Thanks in advance.
>>
>> MikeY
>>
>
>



Nov 17 '05 #5

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

Similar topics

0
by: MikeY | last post by:
Hi everyone, In C#, is there a easy way of display files (ie. mp3 files) to a datagrid? If someone can provide me with some code, or advice I would appreciated it. Thanks in advance. MikeY
2
by: cedced | last post by:
Hello, is it possible to access client files in VB.NET? What? I have doing that but it isn't good (VB.NET take file on pc server and not on pc client): (thanks) Dim fichier As StreamReader ...
1
by: TK | last post by:
I have a file upload control to allow a user to select/upload a file to the server. They need to upload x number of files in one shot because they have to confirm that they are uploading x number...
0
by: Hrvoje Vrbanc | last post by:
Hello, this is a problem I came upon while building a site based on MCMS 2002 but it's not strictly MCMS-oriented: I have a page that displays a certain content in presentation mode but when an...
2
by: JenHu | last post by:
hi, I have a datagrid in my asp.net application, I am using vb.net language. I want to have my last column as a link column, link to text file. The link path is "c:\Temp\" & F_File_Name, which...
3
by: Øyvind Isaksen | last post by:
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....
3
by: Øyvind Isaksen | last post by:
I have a datagrid that displays all files in a folder. It works good, but I need a extra column with a link for choosing image. As shown in the code below I have made an ItemTemplate for this, and...
0
by: hott5hotj | last post by:
Hi guys, I've been working on a project to record video and audio using a standard webcam and microphone. I have been given the basic coding and have it running using wowza media server and apache....
1
by: Avedo | last post by:
Hello! I have a form application with a DataGridView, and an Save/Delete and Cancel button. When the application is opened, it is supplied an XML file that may or may not exist, and display the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.