|
You need to add the table to your page's controls collection.
form1.Controls.Add(testTbl );
'form1' can be the pages Form , or you can use a Panel or PlaceHolder .
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
that was perfect!!
thank you soo much, I could have done with that ages ago for other things, as I actually wanted to add the table to a panel, I just replace form name with panel name.
Thanks again
mark
|
|
|
|
|
hi everyone!
i do have a consol application which will be changed to a service.
i do want the application to check a folder periodically, if there are (new) files in it. if so, then the application does it's duty, if there is nothing (new) then it does nothing.
i am not sure how to do this. first i thought to do it with an endless loop (e.g. while(true)) but will this terminate without an exception when the service is shotdown?
does anyone of you have an idea?
simply checking for an empty folder won't help, because the folder could be empty for some amount of time. so it has to be something like
<br />
while (service_active)<br />
{<br />
Filelist = Directory.GetFiles(sourcepath, searchpattern);<br />
if Filelist.Length > 0<br />
{<br />
}<br />
}<br />
does anyone of you have an idea how to do this?
thanks.
stephan.
|
|
|
|
|
stephan_007 wrote: if there are (new) files in it
Did you consider a FileSystemWatcher based implementation?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.
|
|
|
|
|
Use the FileSystemWatcher[^] class.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
thanks for the hint. but i might have encountered a new problem:
my program (service in the end) checks for files in a folder as long as it is terminated. to start the programm is simple, because i do only have to add the lines of code from my console program to the onstart section.
but what happens, when i stop the service? does it through an exception when the operation is still active? or what do i have to do/implement in the onstop section to let it terminate correctly? do i have to code threads or is there a chance to tell c# to wait until the current operation (periodically check for new files in folder) is finished and shutdown afterwards?
|
|
|
|
|
When the service is stopped/paused, set the EnableRaisingEvents property of the FileSystemWatcher to false . The component will no longer react to file/directory changes. When the service is started/resumed, set the property back to true .
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
thanks for this hint.
i am still wondering if i want to check the directory lets say every 10 sec or lets say every 1 min if this won't consume system resources. because when i do a
while ((lastwatch - now) < 60 secs))
{
// do nothing and wait
}
this consumes systemresources. i think it would be a better solution to send the service to sleep until the new check of the folder. in delphi there is a sleep() function. but is there anything similar in c#? because if there is then i would do the following:
1) sleep for 10 secs, 30 secs or how long ever
2) check directory for files
3) do the operation
and then start at 1 again until the service is stopped.
so is there something similar in c# like sleep() in delphi? because i do want the service to be inactive for some amount of time, check for new files after this time of inactivity and then go back to sleep afterwards.
thanks.
stephan.
|
|
|
|
|
this helped me a lot. but i encountered a new problem: when the file enters the directory which is watched and is still locked by the system copy handler, the file can't be accessed.
e.g. the program watches the directory "watchdir". lets say i copy a file to this directory, then the eventhandler fires already before the file is propperly written to this folder.
this happens, when the program accesses the file which is just copied.
do you have an idea how to handle this? should i delay until it is written?? but in the beginning i do not know how long this will take.
this situation does not occure when there are more files and the file, which is sorted at the top is not the first one handled. meaning lets say, we do have file a and file b. if file b is the last one being written, then there is no problem, if it is file a which is written as the last file, then it is still logged and can't be accessed.
the best solution would be to either ignore or try again some ms later. but what if there is a new file which is sorted before this file. then we have to wait again.
so lets say i do copy the file "file123" then it is accessed at once but might still be protected by the copy handler of windows.
in case of more than one file, if the first file after sorting is accessed then it is the same situation like above, otherwise the error doesn't occure.
any ideas?
|
|
|
|
|
Have a look at SystemEvents.SessionEnding
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
hi
i want to search a word from a textfile and save that in a excel sheet
rajeev kumar sharma
vri software pvt. ltd.
new delhi India
|
|
|
|
|
Hi,
Chekc this.
public static bool SearchWord(string word)<br />
{<br />
StreamReader re = File.OpenText("test.txt");<br />
string input = null;<br />
while ((input = re.ReadLine()) != null)<br />
{<br />
if(input.indexOf(word,0)>0)<br />
{<br />
re.close;<br />
return true;<br />
}<br />
}<br />
re.close;<br />
return false;<br />
}<br />
<br />
Thanks,
Sun Rays
Rate this post if you like answer.
My Articles
|
|
|
|
|
I think u get the data easily form text file.
After getting data from Excel file, u can write in to Excel file
U have to see the following links. Go through this. It may help you a lot.
http://www.codeproject.com/useritems/Write_Data_to_Excel_using.asp
http://www.developerfusion.co.uk/forums/p/29795/109392/
http://support.microsoft.com/kb/306023
G. Satish
|
|
|
|
|
Hello,
I have the following problem: I have a WCF which gets informations from a HTML page, therefor I use a WebBrowser control. But anyway it sucks. How I do it:
1. Starting host => calls method for browsing
2. host gets data request from client => at the WCF a timer becomes started, so all x time units the method for browsing is called and the data is send to the client
1. is no problem, but at 2. I get a ThreadStateException when creating WebBrowser control. The calling thread is not STA and so on. So I thaught, I call the browsing method in a new thread, which StateApartment I set to STA. But it does not work: 1. no problem, but at 2. the thread never comes back. Has anybody an idea what the problem is or how to get it working??? Thanks for your help.
The calling of the browsing method:
Thread parserThread = new Thread(parse);<br />
parserThread.SetApartmentState(ApartmentState.STA);<br />
parserThread.Start(address);<br />
parserThread.Join();<br />
Console.WriteLine("after join");
The browsing method:
private void parse(object addressParameter)<br />
{<br />
string address = addressParameter.ToString();<br />
WebBrowser browser = new WebBrowser();<br />
browser.DocumentCompleted +=<br />
new WebBrowserDocumentCompletedEventHandler(OnDocumentCompleted);<br />
try<br />
{<br />
this.documentCompleted = false;<br />
<br />
browser.Navigate(new Uri(address));<br />
<br />
while (!this.documentCompleted)<br />
{<br />
Application.DoEvents();<br />
Thread.Sleep(1000);<br />
}<br />
<br />
HtmlDocument htmlDocument = browser.Document;<br />
<br />
...<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine(string.Format("Error in parse: {0}", ex));<br />
}<br />
<br />
browser.Dispose();<br />
}
greets
pkoeppe
|
|
|
|
|
Hello Experts,
I am working on a desktop application which is get data from web in the form of the XML. I want to show a progress bar like modal form which will tells end user the status of the progress. Like connecting, Downloading data, parsing and saving data , disconnecting etc.
How will I do that...?
I search a lot on the net but no good solution is found ...
Suppose I got any error while parsing the XML or saving the data then progress bar form should be close and give the proper error message.
I am calling 3-4 different procedure to get data, insert data into the local database and fill the values into the combos and text boxes. So any where error will occurred.
Cross thread operation error is arrived when using threading....
I am facing too many problems please help....
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
Look into the BackgroundWorker class, execute your code in a backgroundworker and use the ReportProgress method to update your user interface.
Standards are great! Everybody should have one!
|
|
|
|
|
Thanks for suggestion ...
Any URL...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
[^]
Standards are great! Everybody should have one!
|
|
|
|
|
Thanks for your reply sir,
Any more idea to show real time processing...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
I'm not sure what you mean by real-time processing; Windows isn't a real-time operating system.
I'm guessing you mean showing progress of an operation while it's executing. Backgroundworkers are the typical way of doing this; they allow you to do some processing while offering the oppertunity to report back to the UI thread via the ReportProgress method. The cross-thread errors you're getting are a result of trying to update user controls on a thread other than the UI thread. You can read about this in most books on .net. In most cases backgroundworkers are the way to go to solve that problem.
Standards are great! Everybody should have one!
|
|
|
|
|
i am working with vs 2005 and i want to call a c# class and methods from Java using JNI. kindly help with some example
|
|
|
|
|
This is more of a Java programming question than a C# one. There is a JNI tutorial here
"You're very clever, young man, very clever," said the old lady. "But it's turtles all the way down!"
|
|
|
|
|
even if it's the wrong forum..
I don't think JNI is the right choice as JNI calls simple C function and C# is even if its name has only one additional letter quite a bit different. You would have to initialize your .NET Runtime on your own (mscoree etc.). I have some doubts that this is the solution you're looking for.
But you might want to check out JNBridgePro!
|
|
|
|
|
|
Hi, I designed a windows applciation by reading mail id's from text file and sending mails. But after sending more than 900 mails i am getting this error.
Exception Occured System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Can any one help reg this error...
I used the code as follows
MailAddress SendFrom = new MailAddress(txtFromAddr.Text);
SmtpClient objSmtpClient = new SmtpClient();
objSmtpClient.Host = "mail.domain.com";
objSmtpClient.Credentials = new System.Net.NetworkCredential("uname", "pwd");
while (!strdata.EndOfStream)
{
_mailId = Convert.ToString(strdata.ReadLine());
if (_mailId != "")
{
MailAddress SendTo = new MailAddress(_mailId);
MailMessage objMailMessage = new MailMessage(SendFrom, SendTo);
objMailMessage.Subject = Convert.ToString(txtSubject.Text);
objMailMessage.Body = Convert.ToString(webBrowser1.DocumentText);
objMailMessage.IsBodyHtml = true;
objSmtpClient.Send(objMailMessage);
}
}
G. Satish
|
|
|
|