|
Yeah, Mircea
Exaclty Something Like That....
Can u give it?
Believe Yourself :->
|
|
|
|
|
Well, maybe if you ask in the web development forum. You are aware that C# hasn't yet made it into the client side arena?
Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.
|
|
|
|
|
The other answer you got was obviously from a rocket scientist...
Why ask for javascript in the C# forum ? You want the web dev or ASP.NET forum ( although your question is not ASP.NET related as such )
http://www.google.com.au/search?sourceid=navclient&ie=UTF-8&rlz=1T4ADBS_enAU225AU226&q=javascript+calculate+age[^]
Quite a few scripts in there that will solve your problem
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
How to read contents of a file(.txt) and display it in a textbox in C# windows form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace TEST
{
public partial class Form1 : Form
{
//string connection;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog objDialog = new OpenFileDialog();
objDialog.Title = "Open .cs File";
objDialog.Filter = "C Sharp Files (*.cs)|*.cs|Text Files (*.txt)|*.txt";
objDialog.InitialDirectory = @"D:\back up d triassic\users\k\Training\ConsoleApplication1";
if (objDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(objDialog.FileName.ToString());
}
listBox1.Items.Add(@"D:\back up d triassic\users\k\Training\ConsoleApplication1");
read();
Open();
}
public static void Open()
{
FileStream file = new FileStream(@"D:\back up d triassic\users\k\Training\ConsoleApplication1\ConsoleApplication1\Program.cs", FileMode.Open, FileAccess.Read);
// Create a new stream to read from a file
StreamReader sr = new StreamReader(file);
// Read contents of file into a string
string s = sr.ReadToEnd();
// Close StreamReader
sr.Close();
}
public static void read()
{
FileStream file = new FileStream(@"D:\back up d triassic\users\k\Training\ConsoleApplication1\ConsoleApplication1\Program.cs", FileMode.Open, FileAccess.Read);
// Create a new stream to read from a file
StreamReader sr = new StreamReader(file);
// Read contents of file into a string
string s = sr.ReadToEnd();
// Close StreamReader
sr.Close();
// Close file
file.Close();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Am stuck here.
Can anybody help me?
j
-- modified at 7:20 Saturday 17th November, 2007
|
|
|
|
|
|
|
ArrayList txtLines = new ArrayList();
// .. now read the text lines from the file with a file stream ....
values.Add (....);
// Bind the data to your listbox's datasource
yourLB.DataSource = values;
yourLB.DataBind();
SkyWalker
|
|
|
|
|
textbox1.Text = File.ReadAllText(objDialog.FileName);
new2pgrmg wrote: objDialog.FileName.ToString(
Why on EARTH would you call 'tostring' on a string ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Why am i getting this exception...
System.TypeInitializationException was unhandled
Message="The type initializer for 'Client.Form1' threw an exception."
Source="Client"
TypeName="Client.Form1"
StackTrace:
at Client.Form1..ctor()
at Client.Program.Main() in C:\Documents and Settings\Luis\Desktop\Server\Client\Client\Program.cs:line 21
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I added this code to it....
In a different class from the main form i have this:
// the try and catch were there already
try{....}// see the finally statement for more info
catch(....){....}// i just warned that all files in the given file will be deleted
//this is the newly added code
finally
{
//path points to a given folder,specify by the Administrator during runtime
//
foreach(string npath in Dfiles)
{
File.Delete(npath);
}
string[] files = Directory.GetFiles(@"C:\Backup", "*.lais");
foreach (string npath in files)
{
File.Copy(npath, path, true);
}
//this is the same i have in the try statement
Dfiles = Directory.GetFiles(@path,".lais");//just to make sure i have all the files now...
if(Dfiles>0){
foreach (string npath in Dfiles)
{
tempor = File.ReadAllBytes(Dfiles[i]);
ms = new MemoryStream(tempor, 0, tempor.Length);
crypto = new CryptoStream(ms, Algorythm.CreateDecryptor(), CryptoStreamMode.Read);
crypto.Read(tempor, 0, tempor.Length);
Images[i] = Image.FromStream(ms);
crypto.Close();
ms.Close();
}
}
}
plus... in the main form i added this:
private static Hook hook = new Hook();
//handle the keys
hook.KeyDown += new KeyEventHandler(hook_KeyDown);
hook.KeyPress += new KeyPressEventHandler(hook_KeyPress);
hook.KeyUp += new KeyEventHandler(hook_KeyUp);
//users are not allowed to do anything with the keyboard
void hook_KeyUp(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = false;
}
void hook_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = false;
}
void hook_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
The hook class is fine, the project class worked fine with it... after i added the finally statement was when the exception came...
What i want is: "If before the application starts a file in the given folder has been modified/altered, a file has been renamed/deleted/created with the same extension" and causes a decripting error i would like that file to be deleted and inform of the deletion without stopping the application. Durin' Runtime i know how to restore files that have been altered/modified but before runtime is quite hard to me!
Please help...
Luis E Tineo S
|
|
|
|
|
Hi!
The exception tells you that the type Client.Form1 could not be initialized correctly, i.e. either the static type initializer (if you have one) or the initialization of a static member threw an exception.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
I want to go to particular line number in a text file directly. How we can do using c#???
Just When i send a line numnber in a function, it directly goes to that line.
please help me........
Thanks in advance
G. Satish
|
|
|
|
|
How do you mean, 'go to the line' ? If you use File.ReadAllLines, you can get an array and use an array index to access the line you want.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I dont want to read a line by lline from a text file.
My requirement is, the cursor directly goes to particular linenumber whatever i passed in function.
Ex: In Notepad, if we use ctrl+G - then it will takes directly to particular line.
In the same way, without reading data from text file line by line, i need to go the cursor directly...
|
|
|
|
|
OK - so you have a textbox and you want to move the cursor to a line ? You have to count the lines in the text file because you can only position the cursor by character index. And you need to count when the text has wrapped, too.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Thank U, The link which u have given is helped a lot, thank u....
|
|
|
|
|
Funny, that article shows how to do what you specifically said that you don't want to do...
Well, that's the only way to do it anyhow. It's impossible to find out where a line in a text file is without reading the previous lines.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I Have 8 usercontrol and 1 form . I am useing the enumeration and dictornay for the selection of the usercontrol.
Form the second usercontrol their are 2 radiobutton . from the second usercontrol next user control selection will be done according to the selection of the radiobutton which will go to different usercontrol according to the radiobutton selection.
please help me
MURALEEKRISHNAN
|
|
|
|
|
what are you trying to ask?
if you just want to get the selected value from the user control then you can do it in multiple ways:
1. declare user control on the master page, declare radiobuttonlist and get the radiobuttonlist from the user control using findcontrol and check the selectedindex in the list
2. add event handler to the usercontrol and get the value in the selectedindexchange event
-----
|
|
|
|
|
Hello experts,
I having a data table with 10,000 records and I have to traverse to each record to find some specific data. For that I have to loop through 10,000 records. So I decided to copy the match column say [Item Name] into the Array list, So I can use arraylist.contains method which will automatically tells record found or not.
And I have to match 5 records every time into the 10,000 records. So my loop is running 50,000 times.
How can copy a single column value of data table into the Array list....?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
why you need array for to do this?
you should use DataTable.Select(expression as string)
one simple example is here:
DataTable table = DataSet1.Tables["Orders"];<br />
string expression;<br />
expression = "Date > '1/1/00'";<br />
DataRow[] foundRows;<br />
<br />
foundRows = table.Select(expression);<br />
<br />
for(int i = 0; i < foundRows.Length; i ++)<br />
{<br />
Console.WriteLine(foundRows[i][0]);<br />
you can change the above code as per your requirement, or look in MSDN for DataTable.Select for more options
-----
|
|
|
|
|
First of all thanks for your reply.
Actually I have to check 5 or more items each time to the 10,000 records of the datatable.
Your solution is good but it will work only for one time
I have to change
expression = "ItemName = 'mobile'";
5 times. Like
expression = "ItemName = 'mobile'";
expression = "ItemName = 'tv'";
expression = "ItemName = 'radio'";
expression = "ItemName = 'computer'";
SO how I do that...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
well you should be able to add multiple expressions using and/or e.g.
expression = "ItemName = 'mobile' or ItemName = 'tv' or ItemName = 'radio' or ItemName = 'computer'";
you can try in also like "ItemName in('mobile','tv', 'radio', 'computer')"
and if you have any primary key in the table then use DataTable.Rows.Find instead of .Select()..
-----
|
|
|
|
|
Dear SABhatti,
Actually I want to know weather or not any item is mismatch. Suppose I have 5 items and 2 items are missing then the functions should say their are 2 items are missing.
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
well you can check the number of rows (foundRows.Length) found and show the message accordingly
-----
|
|
|
|