- Learn how to create a windows service
- Learn how to use Process
- Figure out how to manage files and specifically detect time changes and how to copy.
- Figure out how the cad app 'saves' a file
Last step is more experimental. You should probably save two back ups and alternate as that gives a better chance of one not be bad due to a copy during a write.
Last step also involves figuring out where the file is saved and to which user it belongs.
Users currently work on the files on a blade server
This of course is all dependent on the presumption that the 'server' is in fact windows.
In a C# 2008 desktop application I would like to know how to change the following code so that the files I am looking for can be located.
string Format_Date = DateTime.Now.AddMonths(-1).ToString("MM-yyyy");
String filesaveLocation = null;
filesaveLocation = Path.Combine(ConfigurationSettings.AppSettings["tLocation"], Format_Date);
logging.Error("The location " + filesaveLocation + " does not exist.");
string RFiles = (from path in Directory.GetFiles(filesaveLocation)
let name = Path.GetFileName(path)
where name.EndsWith(".pdf") ||
foreach (String RFile in RFiles)
The code was written for a directory path that looks like the following:
C:\Trans\01-2013 -Note the 01-2013 is for month and year.
Now I am finding out that the file directory stucture in production looks like the following:
R:\Trans\_JAN_2013\A-Sample. Under the A-Sample directory there are 4 separate subdirectories
called: SUB1, SUB2, SUB3, and SUB4.
I was expecting to see the files in one directory instead of 4 separate directories.
Thus can you show me code and/or tell me how you would change the code to accomodae the change in the file directory strucutre?
Next, to get all of the file information from all subdirectories, change the code to build RFiles to be:
var RFiles = from path in Directory.EnumerateFiles(filesaveLocation, "*.*", SearchOption.AllDirectories)
let extension = Path.GetExtension(path)
where extension == ".pdf" || extension == ".xlsx" || extension == ".xls"select path;
It probably isn't necessary to make this into an array if you are just going to iterate over the collection in a foreach. This Linq query will return an IEnumerable<string> which can be used directly in the foreach (unless you will be modifying the values in the collection during the loop).
The string comparisons in the query will be case-sensitive, just like your use of .EndsWith(...).
Now, if all you are going to do is iterate over this collection of filepaths, why not skip building RFiles altogether:
But any 'specified' files that are not located, by definition, will not be in the iteration, so (without seeing what you are doing with the file-paths) I still don't see why you would need the collection.
you can set the "ConfigurationSettings.AppSettings["tLocation"]" somewhere in your code or settings to pick up the root directory. The get all the sub directories using DirectoryInfo, and for each directory in directiories check for files.
In addition the ConfigurationSettings.AppSettings property is obsolete from .Net 2.0 framework, you should not be using that property. Instead you should be using ConfigurationManager.AppSettings.
Can you tell me when the ConfigurationSettings.AppSettings will no longer be supported in visual studio? I would like to know so that I can make the appropriate changes to use the ConfigurationManager.AppSettings settings instead?
I have a DevExpress DatePicker component in my C# windows for application
Jassim Rahma wrote:
and I have a timestamp or datetime field in MySQL.
A timestamp is not the same as a date. Now if the value was carefully manipulated correctly every time it was inserted into the database then you would have a timestamp, NOT a date, which had a fixed time part.
If and only if that is the case then you can get the date part from C# per the other suggestions and then construct the time part and then do an exact match. Probably. (A range is still probably safer.)
If however the time part varies in the database then you MUST use a range check. So if the user picks 2012-12-31 then you create two timestamp values with the following values
start = 2012-12-30 00:00:00
end = 2012-12-31 00:00:00
Then you do a database comparison like the following
there is a exception when i create DirectoryEntry .
DirectoryEntry parent = GetDirectoryEntryByDn(path);
<big><b></b> DirectoryEntry user = parent.Children.Add("CN=" + user_name, "user");</big>
string oGUID = string.Empty;
user.Properties["samAccountName"].Value = user_name;
user.Properties["telephoneNumber"].Value = "15014088110";
user.Properties["streetAddress"].Value = "HZ";
oGUID = user.Guid.ToString();
the program run the line :
DirectoryEntry user = parent.Children.Add("CN=" + user_name, "user")
,the excpetion happened:
the exception InteropServicesCOMException "The specified Directory object is not bound to a remote resource" (and Error code
property is -2147463159)
Alright, I thought this would be simple, but apparently I don't know what I am doing. I have a Rich Text Box that populates upon form load. There are fields that are meant to be updated by text boxes on this form. Here's a snip of the form_load:
So what happens here is the form opens and populates a rich text box with:
CIF = N
Now, what I need to have a button do is update just the items I have defined, in this case chkCIF (a check box) and timeCIF.Text (a textbox). I have a button that's called update, and here's what it looks like.
privatevoid updateButton_Click(object sender, EventArgs e)
//There is a combo box on this form and example is the first optionif (comboInst.Text == "Example")
//Here is where the check box verification is, if it is true it should change the N to Yif (checkCIF.Checked == true)
//This part needs to update the current contents of the email body. Obviously, this isn't working for me so I commented out some examples I tried...//string s = emailBody.Text;//string chkCIF = "Y";//s = s.Replace("N", chkCIF);string theString = emailBody.Text;
theString.Remove(3, 2).Insert(3, "Y");
And there you have it. I just need to be able to update certain defined words from a string with a click of a button. Thanks in advance
Okay.... you are replacing/removing the text but then throwing the result away. You need to set your emailBody.Text back to the string that you have updated.
emailBody.Text = theString.Remove(3, 2).Insert(3, "Y");