|
Hi Luc,
So you I just should install C# Express to open these files? Strange that VS can't open them. I'll give it a try.
Grts from Aalst,
Stieven
|
|
|
|
|
Before installing anything, try these two:
(A) double-click the file in Windows Explorer;
(B) open the Visual Studio versions you have, and let them open an "existing project".
Chances are (1) your file associations have not been set/have been lost, and/or (2) the versions are different and some conversion is needed, which VS will signal when trying (B).
If all this fails, download and install the latest VS C# Express.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi Luc,
Option B worked
Thx for the help!
Grts,
Stieven
|
|
|
|
|
hello,
I am using Visual c# 2005 and sql server2005
In my project I have to use the next date from the current system and have to use it in the where clause of sql query string for that i did the following:
string day = (DateTime.Now.AddDays(1).Day.ToString());
string month = (DateTime.Now.Month.ToString());
string year = (DateTime.Now.Year.ToString());
string date_nextDay = month + '/' + day + '/' + year;
then in sql query my code looks like this:
strQueryString = "select * from view_reservation where date =" + date_nextDay.ToString();
but the problem is sql is not recognizing it although there are some rows in database and whenever I just write the next day date in single quotes by myself it works correctly.Dont kno what to do
|
|
|
|
|
0) You need apostrophes if you do it that way.
1) Why not use System.DateTime.Now.AddDays(1).ToString( "MM'/'dd'/'yyyy" ) ; ?
2) Use a parameterized query and pass in the DateTime rather than making a string that will then have to be parsed.
|
|
|
|
|
strQueryString = string.Format("select * from view_reservation where date = '{0:M/d/yy}'", DateTime.Today.AddDays(1));
Note that the {0:...} part is using curly brackets... string.Format will replace that part with the first additional parameter (Parameter #0), using the format specified. So basically, it'll take Today + 1, format it in the "M/d/yy" form (ex. 9/23/09), and stick it into the string in the right spot.
Also note the single quotes around it... Most databases will require you to put dates inside single quotes.
|
|
|
|
|
In the format for a DateTime, the '/' doesn't mean '/', it means to use the date separator that's set in the operating system, which could be '-' (as it is on my system) or even '.'.
ISO 8601 specifies the use of '-'.
Control panel | Regional and Language Options | Regional Options | Customize | Date | Date separator
|
|
|
|
|
You have alread had the correct answers, about using quotes or better still parameterised query, but you will not always get tomorrow - you add 1 to the day part only. What happens on the last day of the month (or year) - 31st December 2009 will become 1st December 2009 using your code.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
He's using the AddDays method so that's taken care of by the framework - so long as he doesn't try to add to DateTime.MaxValue he'll be OK.
|
|
|
|
|
Only for the day; not for the month and year.
|
|
|
|
|
right now DateTime.Now.AddDays(365+30+1).ToString() returns 25-Oct-2010 1:11:42 on my system.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
The OP added a day when accessing the day, but not when accessing the month and year.
|
|
|
|
|
You're right of course.
And he shouldn't use multiple DateTime.Now calls anyway, it may fail around midnight.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
But he is only adding to the day variable:
string day = (DateTime.Now.AddDays(1).Day.ToString());
string month = (DateTime.Now.Month.ToString());
string year = (DateTime.Now.Year.ToString());
string date_nextDay = month + '/' + day + '/' + year;
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Ah... I saw the AddDays method and assumed that he would be using the returned DateTime instance so didn't look any more at the code.
Using three DateTime instances to create the string representations of a date's constituent parts is a WTF that I wasn't expecting!
|
|
|
|
|
DaveyM69 wrote: DateTime instances
WTF!
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
DaveyM69 wrote: I saw the AddDays method and assumed that he would be using the returned DateTime instance
So did I the first time I read it - just because thats the simple way to get it right
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Oh thankyou all 4 sharing your ideas.My problem is solved
thanks a lot
|
|
|
|
|
First, sorry my poor English.
goal: Modify and print an excel file that is being stored in a directory that is being observed.
Trouble: File Sharing.
Explain:
I have created a Windows service.This service contain a FileSystemWatcher Object who has got an "Created" delegate.
Code Constructor Service
Fsw = new FileSystemWatcher();
Fsw.Path = "c:\\DirListen";
Fsw.Filter = "*.xls";
Fsw.Created +=new FileSystemEventHandler(Fsw_Changed);
When the user save an excel file in "c:\\DirListen" the delegate is raised up and then I must modify the excel file and then print. The problem is that this file is being used by the SSOO (i Think) and I can't use it. I always get errors due to that delegate is raised up before the file has finished to save. I do not want to use timer objects, but with this problem... Please, any suggestion or solution?
Code Delegate
void Fsw_Changed(object sender, FileSystemEventArgs e)
{
try
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
oXL = new Excel.Application();
oWB = oXL.Workbooks.Open(e.FullPath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
object opc = Type.Missing;
oSheet = (Excel._Worksheet)oWB.Sheets.get_Item(2);
oSheet.Activate();
oSheet.Cells[1, 1] = "change";
oSheet.Cells[2, 4] = "another change";
oXL.Visible = true;
oSheet.PrintOut(1, 2, 1, false, "printer", true, false, Type.Missing);
FileStream fs2 = null;
StreamWriter sw2 = null;
oWB.Close(false, e.FullPath, Type.Missing);
oXL.Quit();
foreach (Process p in Process.GetProcessesByName("EXCEL"))
{
p.Kill();
}
}
catch (Exception ex)
{
FileStream fs = null;
StreamWriter sw = null;
fs = new FileStream("c:\\error.log", FileMode.CreateNew, FileAccess.Write);
sw = new StreamWriter(fs);
sw.WriteLine(ex.ToString());
}
}
Many Many Thanks.
regards
|
|
|
|
|
If I understand you correctly, you want to check if a file is in use. AFAIK, the .Net framework doesn't contain a class to do this. What about trying to open a file for exclusive read access, and catching the exception if it fails though?
File.Open(Path, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
Source: here[^]
|
|
|
|
|
Hi,
yes FileSystemWatcher events fire when something changes about a file, which does not mean the file is ready for consumption. When you write a large file, you would get a Created event, and several Changed events. There is no event telling you the file operations have finished.
This basically means you need a delay; I would opt for a Created event handler with a retry loop containing a delay (say Thread.Sleep(100)) and your file operation; the retry loop should try say 10 times, then give up.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Many thanks,
end, It works. I have two possibilities.
1º Adding a Timer Object with an Elapsed delegated: When the delegate "change" that belongs to the FileSystemWatcher object is raised up, then I add the "e.fullname" to a global ListArray of String and reset the timer. Then when the timer is elapsed I consult the ListArray Object and work with entries (Names of Excel files). No problems about File Shared. Then do a clean ListArray object. I have not chosen this option. Not optimal.
2º Using an Thread.Sleep (xxx). Much faster and easier. I did not think about it. Many Thanks Luc Pattyn. I have chosen this option.
Thanks and regards
|
|
|
|
|
you're welcome.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi there,
I am working on projects which requires scanning data from scanner, format data,store selected data from scanned one to database. Any one with idea?
thanks
|
|
|
|
|
Dambod wrote: Any one with idea?
What is the problem then?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|