|
If you are using NTFS, do the following (adding try/catch as appropriate):
public static void Encrypt(XmlDocument ThisDocument, string targetFile) {
FileStream outFile = new FileStream(targetFile, FileMode.OpenOrCreate, FileAccess
.Write, FileShare.None, 0x1000, FileOptions.Encrypted| FileOptions.SequentialScan);
ThisDocument.Save(outFile);
outFile.Close();
}
public static XmlDocument Decrypt(string sourceFile) {
FileStream inFile = new FileStream(sourceFile, FileMode.Open, FileAccess
.Read, FileShare.None, 0x1000, FileOptions.Encrypted | FileOptions.SequentialScan);
ThisDocument.Save(outFile);
inFile.Close();
}
I am currently tired of typing, but I will explain how to do it another way in a bit, in case you are not using NTFS.
-Jeff
|
|
|
|
|
Isn't that user specific?
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Yes, it is user specific... I suggested this because a previous post suggested that the user's password should be used as the key, which would also make it user specific.
-Jeff
|
|
|
|
|
There will be many users accessing this so this isn't viable unfortunately. Thanks for the suggestion though.
|
|
|
|
|
G'day,
A little while back I ran into a similar problem of storing data in a XML file which needs to be encrypted/decrypted as required. I found that using the Cryptography Application Block from Enterprise Library very useful. Purely because I could generate the symmetric key file specific to the user's credential's or machine config. Also you need to consider what happens to the encrypted/decrypted data memory once you have finished with it as well.
I can post some code if you are unfamiliar with the Cryptography Application Block.
To lock a file during Read/Write there is a class within .net that allows you do it. It escapes my mind right now.
cheers,
V
|
|
|
|
|
Downloaded the Enterprise Library - I'll definately look at it in detail. For now, the CryptoStream will suffice.
Thanks.
|
|
|
|
|
Hi,
I've changed my form to use a context menu for basic CRUD operations after using a menu previously.
Now, if you fill out the form (Winform C# 2.0) and right click "save", the last field on the databound form doesn't update the property value in the business object. If I tab through it then the value's updated properly.
So it seems that if the cursor is still focused in that last textbox as I invoke the save, the databinding doesn't update the property and I end up with a blank value in the database.
How can I ensure that the property gets updated if the user doesn't tab out of it?
Seems simple enough but I've gotten myself so confused that I can't think straight, so I ask for help! Thanks.
|
|
|
|
|
Took me quite some time to figure that one out, too.
The update back from control back to BO is after on leave of the control. I notice that if the user move from the control to say a tab page or button, it may not get fired.
Change the update mode to on property changed instead of on leave, ie
this.txtUserCode.DataBindings.Add("Text", UpdateObject, "UserCode", false, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
The BO will get updated on every changes on the control, though.
|
|
|
|
|
Thanks for the response. Your suggestion worked great!! It had me stumped for a while.
|
|
|
|
|
My book on LINQ hasn't arrived yet, so this might be a stupid question or really basic, but anyway...
Is it possible to build a dynamic where clause?
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
|
That's some mighty fine Google work. I'm annoyed, however, that it didn't come up in my googling.
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Yes, I was fiddling abit with dynamic query also.
|
|
|
|
|
Clicking the code link below posted my original reply, and I can't edit it.
Anyway, MatchTypes is an enum where I make use of string's StartWith, EndWith, Contains or Equals functions to filter the search string.
cmbFields contains string fields from the object.
txtValue is the value entered.
I am not able to search using wildcard though ie "ABC*"
IQueryable q = stockPositionDB.StockPositions;
if (this.txtValue.Text.Length > 0 && this.cmbFields.Text.Length > 0)
{
string s = string.Empty;
string match = ((MatchTypes)cmbMatchType.SelectedIndex).ToString();
ParameterExpression param = Expression.Parameter(typeof(StockPosition), "c");
ConstantExpression constant = Expression.Constant(this.txtValue.Text);
MemberExpression prop = Expression.Property(param, typeof(StockPosition).GetProperty(cmbFields.Text));
System.Reflection.MethodInfo mi = s.GetType().GetMethod(match, new Type[] { typeof(string) });
MethodCallExpression call = Expression.Call(prop, mi, new Expression[] { constant });
//BinaryExpression filter = Expression.Equal(prop, constant);
LambdaExpression pred = Expression.Lambda(call, param);
MethodCallExpression expr = Expression.Call(typeof(Queryable), "Where", new Type[] { typeof(StockPosition) }, Expression.Constant(q), pred);
q = q.AsQueryable().Provider.CreateQuery<stockposition>(expr);
this.bindingSource1.DataSource = q;
}
|
|
|
|
|
I am attempting to resolve a domain name to it's ip address, but am having a problem. When I call 'Dns.GetHostEntry("www.giftwich.com");', then try to connect to this ip, I get internet error 400, "The Page Cannot be Found". I think it is because the site is not the only one on a particular computer, or perhaps I am getting the ip address of the DNS server for that host. I don't know, but can anyone shed some light on how to get around this so I can connect to a site like this through the ip address? Thanks,
-Jeff
|
|
|
|
|
If you can ping the returned address, then the server is a Virtual Server in that it's mappings are based on name (multiple domains on one ip address).
Try it the other way around and feed the ip address in and see if you get the dns name (giftwich.com).
|
|
|
|
|
I don't get the dns name... it is something different. Since it is a virtual server, does that mean I cannot connect to it directly using the ip address?
-Jeff
|
|
|
|
|
Yeah with a virtual server, the IP address will only get you to the server itself. From there, it's routed based on the header info for the file area for the site. It's doable but complicated. Not sure exactly what you're trying to do but maybe set up two methods. One connects via the dns name, the other by IP address. If IP address returns a 404, then connect by dns name instead.
|
|
|
|
|
Ok, thanks for the help!
-Jeff
|
|
|
|
|
Can anyone tell me why strSpd2 in the example below ends up being a
blank string when formatting a zero value? It would seem to me that
strSpd2 should end up being "0.0"
double val1 = 14.38009
double val2 = 0.0;
string strSpd1 = "";
string strSpd2 = "";
// This formats correctly. strSpd1 = "14.4"
strSpd1 = String.Format("{0:##.#}", val1);
// This does not format. strSpd2 = "" Why is this blank and not "0.0"
strSpd2 = String.Format("{0:#.#}", val2);
Craig
|
|
|
|
|
Yes, the # means "Put a digit here if it is significant". Since leading and trailing 0's are not significant, you are getting no value. Use, "{0: 0.0}" as your format specifier, as described here[^].
-Jeff
|
|
|
|
|
have a menu strip in my application with:
File Edit View Tool
Under my view heading I have a option to see end of line characters, what I want do is have it so the user knows when this has been clicked on, the problem is that I have an image in the TooStripMenuItem so you can't see the check mark when it is clicked. Any ideas?
|
|
|
|
|
Perhaps you could change...
1. The style of the menu item (ie, bold means active, normal means inactive)
2. The image associated with the menu item
3. The text for the menu item (Like "Show Newlines" vs. "Hide Newlines")
Hope this helps,
-Jeff
|
|
|
|
|
Hi all,
Here is my question. I have 3 forms,
FormMain
Form1
Form2
Form1 and Form2 are loaded into panels on FormMain. I need to access Form2 from Form1. Say I need to disable Form2 if a button is clicked on Form1 BUT I need to do it from Form1 (it is easy to control the instances from FormMain but that is not what I need).
Any suggestion?
Thanks!
-Kam
|
|
|
|
|
Naz wrote: I need to access Form2 from Form1. Say I need to disable Form2 if a button is clicked on Form1 BUT I need to do it from Form1
Pass form2 to the constructor of form 1 on load.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|