|
I need some help getting base data from an object.
Here is the code that I am using:
l_oAttributes = type.GetCustomAttributes(true);<br />
<br />
foreach (Attribute attribute in l_oAttributes)<br />
{<br />
Object l_oTest = l_oAttributes[0];<br />
}
etc etc...
The information I need is in the base of the l_oTest (ie ColumeID and such), how can I access this information?
Thanks
|
|
|
|
|
RussBus wrote: how can I access this information
I guess l_oTest is a type other than Object so you need to cast it and then access it's public members, or am I missing something?
|
|
|
|
|
Do I cast it as the type of attribute it is? How would I do this?
|
|
|
|
|
If you know the base type of l_oTest, simply convert it to that type...
KnownBaseType kt = l_oTest as KnownBaseType;
if (kt != null) {
// Do Something
}
If you don't know what the base type is, but you know you want to get or set the value of some property, use reflection...
using System.Reflection;
...
PropertyInfo pi = l_oTest.GetType().BaseType.GetProperty("PropertyName");
if (pi.CanRead) {
PropertyReturnType result = (PropertyReturnType)pi.GetGetMethod().Invoke(l_oTest, null);
}
Is this what you need?
Jeff
|
|
|
|
|
I still don't get the value.
I want to get the value for ColumnID, when I use you code I get ColumnID but not the value for it.
|
|
|
|
|
NM you are a programming god, your code works
|
|
|
|
|
Post the part of your code that isn't working like you need it to, and explain exactly what you expect or need to get from it so I can help further.
Jeff
|
|
|
|
|
I am writing a small program in C# that has to count the number of image files and the number of text files in a single folder and to come up with a seperate value for each type of file. The code has to be general enough to accomodate changes to the number of image or text files in a given folder depending upon the designated path.
At present, my approach has been to specify the path via code such as @"C:\My Program\Folder";
Any help would be appreciated.
|
|
|
|
|
Read the first thread in the forum titled "How to get an answer to your question". Pay attention to item #2
|
|
|
|
|
if you know the file type, the easiest way is use Directory.GetFiles(path, "*.ext"); it will return a string array, you can get the file count using Properties of Length
|
|
|
|
|
Thank you so much.
As I said before, I am on this like you can't believe.
|
|
|
|
|
Then you can use System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); to get all supported image format, or you could create your own image format array to loop the extension as I mention(and what you did).
|
|
|
|
|
You people are great!
I have solved much of the program's display requirements... thanks to all of your assistance and pointers.
|
|
|
|
|
You can use DirectoryInfo to get all files in a specific folder, you can also get it to only return files with specific file extensions, so look up how to use directoryinfo, and start making a list of all the file extensions that your image files have.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Thank you so much.
I'm gonna be all over this like a fat kid on candy.
|
|
|
|
|
I store path of images in Sql Server Database.Now I want to display those images to DataList.How can I do that ?
nothing
|
|
|
|
|
Make the DataList use a second DataTable as the source for its info, instead of the one you read in from the DB. Note that I did not use a compiler to write this, so you will need to modify it as needed, but I think the logic should work.
// Assume the other dataTable is called "original"
// Perform this op as soon as you read the data from the DB
DataTable dt = new DataTable();
foreach (DataColumn dc in original.Columns) {
if (dc.Name == "WhateverYouCallTheImageColumn") {
dt.Columns.Add(new DataColumn(dc.Name, typeof(Bitmap)));
} else {
dt.Columns.Add(new DataColumn(dc.Name, dc.Type));
}
}
foreach (DataRow dr in original.Rows) {
DataRow newRow = new DataRow();
foreach (DataColumn dc in original.Columns) {
// populate newRow, opening the images when you arrive at that column
}
dt.AddRow(newRow);
}
DataView dv = new DataView(dt);
Jeff
|
|
|
|
|
I'm looking for any insight on how to modify the summary information of a file (title, subject, author etc.). I've looked through System.IO and can't seem to find anything that will do this. I want to do this for any type of file (primarily office docs and pdfs), so dsofile doesn't quite do the trick.
Thanks
|
|
|
|
|
This information (for office documents) is actually stored in OLE Structured Storage (as part of the file). The only way to modify this would be to either access the file direct or to use COM Interop with the Office applications.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I can modify all of the properties for office docs using the dsofile.dll which isn't a problem. Is there a generic way to modify the file summary for any type of document, not just office docs?
|
|
|
|
|
I'm sure I just pointed out that the summary was stored in the file itself - i.e. wasn't easily accessible metadata. So, no. Different files types have their own ways of storing this information.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
File.SetCreationTime(); That kind of stuff?
Nevermind. I see you were talking about author, description, etc
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
|
Hi!
Is it possible to change the font in a console application?
Like iif I have a game where I pick up a megaphone, and want to have a webbding character that happens to look just like a megaphone. Is this possible?
thanks Daniel
Dan Steeve
|
|
|
|
|
Hi Dan,
I once did color changes on a Console app, that took some P/Invoke using the following
prototypes and definitions:
[DllImport("kernel32.dll")]
public static extern bool SetConsoleCtrlHandler(ConsoleControlHandler e, bool add);
[DllImport("kernel32.dll")]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll")]
public static extern bool SetConsoleTextAttribute(IntPtr windowHandle, int attrib);
[DllImport("KERNEL32.DLL")]
internal static extern int GetConsoleScreenBufferInfo (IntPtr hConsoleOutput,
ref CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
public delegate bool ConsoleControlHandler(ConsoleControlEvent consoleEvent);
public enum ConsoleControlEvent {
CtrlC=0,
CtrlBreak=1,
CtrlClose=2,
CtrlLogoff=5,
CtrlShutdown=6}
public enum TextColor {
Black=0,
DarkBlue=1,
DarkGreen=2,
Brown=4,
DarkMagenta=5,
DarkYellow=6,
Gray=7,
Blue=9,
Green=10,
Cyan=11,
Red=12,
Magenta=13,
Yellow=14,
White=15,
Unknown=16
}
This should get you going.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|