|
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
|
|
|
|
|
Satish - Developer wrote: after sending more than 900 mails
This may be your problem. I rather imagine your ISP wwill have terminated the SMTP connection after you sending so many emails. You should check with them about their bulk email policy.
"You're very clever, young man, very clever," said the old lady. "But it's turtles all the way down!"
|
|
|
|
|
Can u explain reg this... where i have to check for this...
|
|
|
|
|
You'll need to check with whoever runs the SMTP server that you are using to send your email. Many ISPs have rules about the number of emails you can send at a time to prevent spamming. I assume you have the permission of the people you are emailing?
"You're very clever, young man, very clever," said the old lady. "But it's turtles all the way down!"
|
|
|
|
|
When i run the Email application, automatically the to-address is repeating.
ie.
TO: satish.g@techgene.com; kiran@techgene.com; madhu@techgene.com;
the above line is for one mail.
And for next mail
TO: satish.g@techgene.com; kiran@techgene.com; madhu@techgene.com; suchi@techgene.com
like this for mail to mail.. the toaddress is repeating.
But when i debug this, there is no loops to get this, and also when sending mail
there is only one id in to-address?
any idea ? what's the reason by coming like this?
there is no loop to come like this.
u can see the code in above posting
|
|
|
|
|
Satish - Developer wrote: objMailMessage.Body =
Hi,
in objMailMessage.To set only one ID. and all other ID set in objMailMessage.Cc
Try it.
Thanks,
Sun Rays
Rate this post if you like answer.
My Articles
|
|
|
|
|
Hi, Please see the code below.
I am reading mailid's from text file. In each line there is only one mailID.
so "_mailid" contains only 1 id.
now can u suggest how to put cc
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);
}
}
|
|
|
|
|
Hi,
Satish - Developer wrote: MailAddress SendFrom = new MailAddress(txtFromAddr.Text);
without doing this. Just create mailmessage object.
MailMessage objMailMessage = new MailMessage();<br />
objMailMessage.To = "toUser's email ID";<br />
objMailMessage.Subject = Convert.ToString(txtSubject.Text);<br />
objMailMessage.Body = Convert.ToString(webBrowser1.DocumentText);<br />
objMailMessage.IsBodyHtml = true;<br />
<br />
SmtpClient objSmtpClient = new SmtpClient();<br />
objSmtpClient.Host = "mail.domain.com";<br />
objSmtpClient.Credentials = new System.Net.NetworkCredential("uname", "pwd");<br />
<br />
objSmtpClient.Send(objMailMessage);<br />
Just try this. If you are getting error then u must have to chekc for smtp setting of server.
Thanks,
Sun Rays
Rate this post if you like answer.
My Articles
|
|
|
|
|
is your PORT number correct...?
spaps
|
|
|
|