473,772 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1533
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.co m

"MikeY" <mi*******@yaho .com> wrote in message
news:RH******** ***********@new s20.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_Cli ck(object sender, System.EventArg s e)
{
System.IO.Direc toryInfo dir = new System.IO.Direc toryInfo(@"C:\D ocuments
and Settings\MikeYA dmin\Desktop\Mu sic 1");

DirectoryInfo[] myDirectory = dir.GetDirector ies();
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.c om> wrote in
message news:eu******** ******@TK2MSFTN GP10.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.co m

"MikeY" <mi*******@yaho .com> wrote in message
news:RH******** ***********@new s20.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******** ***********@new s20.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_Cli ck(object sender, System.EventArg s e)
{
System.IO.Direc toryInfo dir = new System.IO.Direc toryInfo(@"C:\D ocuments
and Settings\MikeYA dmin\Desktop\Mu sic 1");

DirectoryInfo[] myDirectory = dir.GetDirector ies();
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.c om> wrote in message news:eu******** ******@TK2MSFTN GP10.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.co m

"MikeY" <mi*******@yaho .com> wrote in message
news:RH******** ***********@new s20.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******** *****@TK2MSFTNG P11.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******** ***********@new s20.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_Cli ck(object sender, System.EventArg s e)
{
System.IO.Direc toryInfo dir = new System.IO.Direc toryInfo(@"C:\D ocuments
and Settings\MikeYA dmin\Desktop\Mu sic 1");

DirectoryInfo[] myDirectory = dir.GetDirector ies();
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.c om> wrote

in
message news:eu******** ******@TK2MSFTN GP10.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.co m
>
> "MikeY" <mi*******@yaho .com> wrote in message
> news:RH******** ***********@new s20.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
225
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
2046
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 Dim name As String
1
2557
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 files for processing. So I do not want the files to be uploaded until the user presses a submit button verifying that they want to submit x number of files for processig (processing refers to me doing something to the files once uploaded). Catch...
0
1414
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 editor clicks "Switch To Edit Site" in MCMS console on the page, the page displays a different content, an interface that editor use for upload and deleting files on the web server. There are no problems with the upload but there is a problem...
2
2376
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 is the 2nd column. For example, the data grid should like this:
3
1337
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. Example: The file "123456_myfile.jpg" shoult be displayed like this: "myfile.jpg" ---------------------------
3
2071
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 what I need to do is to put the filename in the CommandArgument. How do I do that?? Is this the right way to do it, or is it a smarter way to put the filename in a session-variable when clicking on the "Use this image"-LinkButton ? ...
0
1376
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. When I press record the video is recorded and when I press send, a filename is created for it along with a thumbnail image, and the date and duration of the video which is stored in a datacontainer on the right of the main interface. When I select...
1
5366
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 contents. Regardless of whether or not the file exists, the user must be able to modify the data in each cell in the DataGridView, along with being able to add or remove rows. When the Save button is clicked, the contents of the DataGridView must be...
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.