|
Try this.....
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK)
{
DirectoryInfo di = new DirectoryInfo(fbd.SelectedPath);
if (di.Exists)
{
String[] files;
files = Directory.GetFiles(fbd.SelectedPath);
foreach (string file in files)
{
}
}
}
Have a Happy Coding.....
|
|
|
|
|
Thanks a lot for your help King Julien.
after looping through the files, I read each line in a file and save everything to the database. I have a date field that is sometimes empty I've initialized it to
DateTime DateOpened = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
Now, when I'm reading the date
if (line.Contains("Date Opened :"))
{
line = reader.ReadLine();
DateOpened = Convert.ToDateTime(line);
line = reader.ReadLine();
}
I get a FormatException error: String was not recognized as a valid DateTime. Please advice where I did wrong.
Thanks.
|
|
|
|
|
Hi NOPO,
As i could see, you are passing the entire line to the ToDateTime() function.
If the line have a string similar to a date time, the function converts it to the correct DateTime.
I am not sure what string you have in the line. If it contains variety of strings, parse it first and pass it to the Conversion function.
As from the microsoft documentation,some of the valid strings that could be converted are
dateString = "05/01/1996";
ConvertToDateTime(dateString);
dateString = "Tue Apr 28, 2009";
ConvertToDateTime(dateString);
dateString = "Wed Apr 28, 2009";
ConvertToDateTime(dateString);
dateString = "06 July 2008 7:32:47 AM";
ConvertToDateTime(dateString);
dateString = "17:32:47.003";
ConvertToDateTime(dateString);
dateString = "Sat, 10 May 2008 14:32:17 GMT";
ConvertToDateTime(dateString);
dateString = "2009-05-01T07:54:59.9843750-04:00";
ConvertToDateTime(dateString);
Wish you a good luck....
Have a Happy Coding.....
|
|
|
|
|
line variable contains 19990723 as a date, how then do I convert such date?
|
|
|
|
|
19990723??????
Are you sure thats a date??????
Is it manually entered in the file or a system generated value????
Have a Happy Coding.....
|
|
|
|
|
If it's YearMonthDay, then use DateTime.ParseExact and look into format strings - they're used for the parsing mechanism
|
|
|
|
|
|
Ok I have a situation where I have my main form that opens at the beginning.
Once that form opens there is a button Add Time and a label ttlTime which shows the total amount of time stored.
Once Add Time is clicked a form opens. In that form there are buttons that have letters on them.
The user can click on any button and it then closes that form and opens the actual AddTime form.
In this AddTime form there are comboboxes that allow you to select certain things. Once the form is filled out.
You click on Submit and it posts data to an xml file which stores the hours and then closes the AddTime form and shows the Main form again. I would like to be able to somehow call an event on closing the AddTime form or the showing of the Main form to update the ttlTime label so that they can see the updated time without having to click on a refresh button or something similar. If anyone knows of a way to accomplish this. It would be a great help. I have tried doing some get/set and I cant seem to figure out how to get the label updated.
Thanks for the help.
|
|
|
|
|
use Form.Closing or Form.Closed event to trigger a delegate in which you can do all the required work (updating ttlTime etc.....)
Have a Happy Coding.....
|
|
|
|
|
The issue is I can actually do what i want by.
opening the main form.
Then open AddTime form directly and it will update the label using a custom event.
But the problem is I cant seem to figure out how to open the filter window first then when the letter is selected it opens the AddTime form then when i close the AddTime window have it update the label ttlTime then.
In Basic words I want to be able to.
1. open main form
2. open filter form off of main form
3. open addtime form off of filter form
4. when I click on the close button event I would like to update the label.
pretty much it. I am just not sure code wise how to accomplish this.
Thanks for your quick reply btw.
|
|
|
|
|
|
Thanks the answer helped but I solved it by doing this.
Thanks to a post here http://forum.codecall.net/c-programming/515-c-calling-parent-functions-child-form.html#post2214[^]
Void's post...
-Example-
MainForm Code:
namespace CallParentFuncFromChildChild
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Child1 child1 = new Child1(this);
child1.Show();
}
public void msgme()
{
MessageBox.Show("Parent Function Called");
}
}
}
Child1 Code:
namespace CallParentFuncFromChildChild
{
public partial class Child1 : Form
{
private MainForm m_mainForm;
public Child1(MainForm mainForm)
{
InitializeComponent();
m_mainForm = mainForm;
}
private void button1_Click(object sender, EventArgs e)
{
SubChild1 subChild1 = new SubChild1(m_mainForm);
subChild1.Show();
this.Close();
}
}
}
SubChild1 Code:
namespace CallParentFuncFromChildChild
{
public partial class SubChild1 : Form
{
private MainForm m_mainForm;
public SubChild1(MainForm mainForm)
{
InitializeComponent();
m_mainForm = mainForm;
}
private void button1_Click(object sender, EventArgs e)
{
m_mainForm.msgme();
this.Close();
}
}
}
Thanks again for the help and I hope this helps someone. :]
|
|
|
|
|
Hi programmers,
I'm working a software called VeriLook in C#. I had some problems saving the image to a file after capturing the image.
namespace prac_8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CameraMan cameraMan = new CameraMan(null);
Console.WriteLine("Found cameras (id, default resolution, automatic settings):");
foreach (Camera camera in cameraMan.Cameras)
{
CameraVideoFormat videoFormat = camera.VideoFormat;
Console.Write("\t{0}, {1}x{2}x{3:f2}, {4}",
camera.ID, videoFormat.FrameWidth, videoFormat.FrameHeight,
videoFormat.FrameRate, camera.AutomaticSettings);
camera.StartCapturing();
NImage image = camera.GetCurrentFrame();
Bitmap bm = image.ToBitmap();
videoControl.Image = new Bitmap(bm);
}
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap bm = videoControl.Image;
NImage image = NImage.FromBitmap(bm);
NGrayscaleImage grayscale = (NGrayscaleImage)NImage.FromImage(NPixelFormat.Grayscale, 0, image);
NLExtractor extractor = new NLExtractor();
NleDetectionDetails details;
NleExtractionStatus extractionStatus;
NLTemplate template = extractor.Extract(grayscale, out details, out extractionStatus);
if (details.FaceAvailable && details.EyesAvailable)
{
MessageBox.Show("Found face and eyes!");
}
if (extractionStatus != NleExtractionStatus.TemplateCreated)
{
MessageBox.Show("Extraction failed!");
return;
}
NLTemplate compressed = extractor.Compress(template);
if (compressed == null)
{
Console.WriteLine("Face template compression failed!");
return;
}
BinaryWriter writer = new BinaryWriter(new FileStream(args[0], FileMode.OpenOrCreate, FileAccess.Write));
writer.Write(compressed.Save());
writer.Close();
}
}
}
Basically this is what i have
I had encountered an error with
"The name 'args' does not exist in the current context." line 81
what does it mean? and what can i do to solve it? what should i put down?
thanks!~
|
|
|
|
|
Since you don't use "args" anywhere in this code, and you don't specify which line the error occurs on, I can only assume that it's a problem with the library you're using.
|
|
|
|
|
Dave Kreskowiak wrote: you don't specify which line the error occurs on
Hi,
If you read carefully the error is on line 81 which i had specified.
|
|
|
|
|
|
Do you really expect us to count the lines?
Highlight (put in bold) or mark with comment or even repeat the line that gives the error.
|
|
|
|
|
Oh! You mean that TINY little comment on the end of the line?? The one that got cutoff because the line was too big to fit on the monitor I was on??
OK, I'll say it again. Nowhere in this code is "args" defined. So, the error is correct. You're using "args" in that line you barely pointed out, but nowhere in this section of code did you define it.
|
|
|
|
|
RogerLum wrote: BinaryWriter writer = new BinaryWriter(new FileStream(args[0], FileMode.OpenOrCreate, FileAccess.Write)); //line 81
Why did you use arg[0] and never specified the value in the first place?
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
}
|
|
|
|
|
8kelvin wrote: Why did you use arg[0] and never specified the value in the first place?
8.Kelvin(){ while (!(the machine can program itself)) Wont_stop_coding = true;}
like i said,
i have little knowledge of c#, and therefore coming to learn over here, if not i won't be even asking in this forum at all.
|
|
|
|
|
RogerLum wrote: i have little knowledge of c#
Then why are you choosing such a complex task to learn C# ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I'm assuming that since you never declared the arg variable that it's the commend line arguments you want here.
Use:
Environment.GetCommandLineArgs().GetValue(1).ToString();
|
|
|
|
|
By the look of things, you've copy pasted some code from an example, without really understanding it.
in your example, args[] was probably the values from the command line. It doesn't look like you've got a command line application here, and the args[] array doesn't automagically propogate itself around the program - you'd need to copy it into a member variable, or pass it as an argument into your functions.
In this case, you need to replace the bit that reads "args[0]" with the filename you want to save the image to,
|
|
|
|
|
ok so I'm using
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
to click at a location on a WebBrowser object in my program
it's working fine for regular websites, but when I try to use it to click onto a site which is a flash program it doesn't register as having clicked
I don't know where the error is occuring but the site doesn't know that it's been clicked in this case
any tips?
|
|
|
|
|
If your'e trying to click inside a Flash object, it won't work. SendMessage only sends messages Win32 window handles. Since Flash isn't a window in the Win32 sense, nothing will happen.
|
|
|
|