|
Hi,
I have used below code to log in to my network drive, before using this code every time when i manually access the network folder it asks me credential to login. But after executing this code the network drive is not asking for any credential when i manually locate to the network drive. Any idea what is happening
[DllImport("advapi32.dll")]
public static extern int LogonUserA(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken(IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
|
|
|
|
|
Hello Experts,
This is my first attempt to use regular expression for a sequence of string.. i am partially successful but wants to get things validated...
I have a sequence of character like
"ABC 34 DEX 456 NT 456 TEXT rt st NEWTEXT 4564"
All caps are identifier and subsequent is the value like the value of ABC is 34 and DEX is 456....
Problem:
i need to replace the value of TEXT with *
1)it can be null
2)its name itself can change like TEXTVAL or TEXT:
3)there could be 2 or 3 space after TEXT
4)But the max length of value would be 5 and min would be 2
5)it can accept space too at any position in the value
Considering all above i reached in the conclusion that it would be hard to find number of element for Value..as space can be from value or from field...
what i have decided i will insert five stars(*****) max length of TEXT value...
so to achieve this i am using
Quote: Regex _regex = new Regex(@"/TEXT/([a-z0-9\-\ ]+)\ $");
for each field TEXT,TEXT: and TEXTVAL.. but i am not very much convinced with the approach ..can some body help me here..
Thanks,
Tasu
vikas da
|
|
|
|
|
I'm not sure exactly what you are trying to do! Perhaps an example of your input and output strings would help? Preferably using "real" data, rather than "mock up"?
The trouble is that your example fixes the word "TEXT" and will detect in two places in your example, so it's difficult to work out exactly what you are trying to achive:
TEXT rt st NEWTEXT 4564 is one match,
and
TEXT 4564 is also a match.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Perhaps i could have provided this before..
Quote: "FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN 12345 ADDLINE1....."
"FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN # 12345 CITY....."
"FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN: 123 5 COUNTRY....."
"FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN NUMBER ADDLINE1....."
So in Above the value of PIN value needs to be masked with (*)...if it has some value..
Pin can be alphanumeric and can have space also.
above streams are from different screen so they do not have consistency in name of PIN as it can be PIN: or PIN # or PIN NUMBER or simply PIN...
The ADDLINE1 is also not fixed and it can change to CITY,Country etc
Now i have to extract the value of PIN|PIN:|PIN #|PIN NUMBER and need to replace it by ***** in all the scenario if it contains a value.
Let me know if you still have some doubts..
vikas da
|
|
|
|
|
That's really quite nasty.
If the PIN can only be numeric, then it's not too bad - but if it does contain alpha characters and spaces, then you can't find a PIN in the last example: ADDLINE1 could be PIN data...
For numeric it's ok:
public static Regex regex = new Regex(
"(PIN\\s?(\\#|:|NUMBER)?\\s?)([\\d\\s]+)",
RegexOptions.Multiline
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
public static string regexReplace = "$1 ****";
...
string result = regex.Replace(InputText,regexReplace); buit with alphanumerics? I'm not sure it can be done...
But I do love Expresso [^] - it makes working out and testing these things sooooo much easier!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Based on your sample data and description, this pattern will match the three PIN numbers:
(?<=(PIN|(PIN\s+\#)|(PIN:)|(PIN NUMBER))\s+)\b[\w\s]{2,5}\b
You can then replace it with "*****" to mask the values:
Regex pinNumberPattern = new Regex(@"(?<=(PIN|(PIN\s+\#)|(PIN:)|(PIN NUMBER))\s+)\b[\w\s]{2,5}\b", RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
string input = @"FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN 12345 ADDLINE1.....
FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN # 12345 CITY.....
FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN: 123 5 COUNTRY.....
FIRSTNAME Tasu LASTNAME Mishra DOB 02011982 PIN NUMBER ADDLINE1.....";
string output = pinNumberPattern.Replace(input, "*****");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard Deeming and OriginalGriff ...I will test the various scenario and update you the same.
Thank you so much for the help
vikas da
|
|
|
|
|
Why are they called Generics in "modern" languages, but Templates in C++?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Possibly because they're not quite the same thing.
Key differences between generics and C++ templates:
- Generics are generic until the types are substituted for them at runtime. Templates are specialized at compile time so they are not still parameterized types at runtime
- The common language runtime specifically supports generics in MSIL. Because the runtime knows about generics, specific types can be substituted for generic types when referencing an assembly containing a generic type. Templates, in contrast, resolve into ordinary types at compile time and the resulting types may not be specialized in other assemblies.
- Generics specialized in two different assemblies with the same type arguments are the same type. Templates specialized in two different assemblies with the same type arguments are considered by the runtime to be different types.
- Generics are generated as a single piece of executable code which is used for all reference type arguments (this is not true for value types, which have a unique implementation per value type). The JIT compiler knows about generics and is able to optimize the code for the reference or value types that are used as type arguments. Templates generate separate runtime code for each specialization.
- Generics do not allow non-type template parameters, such as
template <int i> C {} . Templates allow them. - Generics do not allow explicit specialization (that is, a custom implementation of a template for a specific type). Templates do.
- Generics do not allow partial specialization (a custom implementation for a subset of the type arguments). Templates do.
- Generics do not allow the type parameter to be used as the base class for the generic type. Templates do.
- Templates support template-template parameters (e.g.
template<template<class T> class X> class MyClass ), but generics do not.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh wow, I didn't realize it was so complex. Thank you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
-
modified 13-Feb-14 13:20pm.
|
|
|
|
|
Lots of us can, and are willing to, help with this.
HOWEVER, you have to start by trying so solve it and then, when you have a specific difficulty, come back and ask a clear question about your issue, showing us the relevant code for the issue and any error message(s) you are getting. (Don't just say "it doesn't work".)
Then we'll try to assist.
We will NOT do your work for you.
|
|
|
|
|
|
Why did you remove the content of your question? Never delete or remove content of your question if someone replied.
He told you to update the question with more details. So update your question with needed details, you'll get answer.
thatrajaCode converters | Education Needed
No thanks, I am all stocked up. - Luc Pattyn
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
|
|
|
|
|
I will make first a start if i have question then i will add a new topic
|
|
|
|
|
Restore the content so that others could understand about the question. Still you could use same question for answers if you want. After restore you could get some ideas from member then you could start easily & come here again for new questions. FYI Some guidelines for posting questions in the forums[^]
And hereafter please don't remove the content or question.
thatrajaCode converters | Education Needed
No thanks, I am all stocked up. - Luc Pattyn
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
|
|
|
|
|
Hi,
I have a panel which is not visible to begin with. this panel had a static text, and a dropdownlist which is loaded dynamically.
On Postback, when the dropdownlist keeps disappearing, but i can still see the static question. On viewing in the firebug, the visibility for this dropdown is set to hidden. I keep setting it to visible but the dropdown does not show.
any ideas?????
|
|
|
|
|
vkEE wrote: any ideas? Yes, this seems more appropriate to the ASP.NET forum.
Veni, vidi, abiit domum
|
|
|
|
|
Hi All,
I am facing "Out of Memory" issue when I am populating TreeView hierarchy using XML. Our XML structure is very complex and it is not in fix format. There are multiple level of child nodes. I am using recursion to iterate XML and populate TreeView structure. I tried to call GC.Collect() to clear memory but still it is throwing same error.
I am using C# of .NET framework 3.5 for development.
I will appreciate if you can help me to find solution for this.
I'm providing the Code, Which I'm using for populating the treeview, below
private void addTreeNode(XmlNode xmlNode, TreeNode treeNode)
{
string attribute = "";
treeView1.ImageList = imageList1;
treeViewResponse.ImageList = imageList1;
XmlNode xNode;
TreeNode tNode;
XmlNodeList xNodeList;
foo.MoveToFollowing(XPathNodeType.Element);
namespaces1 = foo.GetNamespacesInScope(XmlNamespaceScope.All);
if (xmlNode.HasChildNodes)
{
treeNode.ImageIndex = 0;
treeNode.SelectedImageIndex = 0;
xNodeList = xmlNode.ChildNodes;
for (int x = 0; x <= xNodeList.Count - 1; x++)
{
xNode = xmlNode.ChildNodes[x];
treeNode.Nodes.Add(new TreeNode(xNode.Name));
tNode = treeNode.Nodes[x];
//treeNode.Nodes[x].ImageIndex = -1;
addTreeNode(xNode, tNode);
}
}
else
{
treeNode.ImageIndex = 1;
treeNode.NodeFont = new Font("Arial", 8, FontStyle.Bold);
treeNode.SelectedImageIndex = 1;
treeNode.Text = xmlNode.OuterXml.Trim();
}
}
Thanks in advance.
Regards,
Rajeev
|
|
|
|
|
It's probably not a memory problem.
OutOfMemory can also be thrown if you exhaust the handle pools. How many items are in this TreeView?
The common technique to avoid spending a ton of resources and time populating a TreeView is to just populate the top-level items, putting dummy placeholder items in the folders so you get a expand button next to the folder. When the folder is expanded, remove the dummy item and repopulate that folder with its real child items, including more dummy filled folders as required.
|
|
|
|
|
Member 7680434 wrote: xmlNode.OuterXml.Trim(); You don't want to create a new large string and put that in a node; it is a new object that will consume memory.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
If you don't take the trouble to use the CP editor, and enclose your code in the right tags, and format it so it's readable, then you are discouraging people from even trying to assist you.
In addition, it's probably going to be hard to estimate the source of an out-of-memory error without knowing something about the size of your data, and the machine spec on which you are trying to create the TreeView.
Something that "jumps out at me," just glancing at your code is that you are executing code that modifies the entire TreeView inside your recursive procedure that builds it, like: treeView1.ImageList = imageList1;
Also, I don't see you actually adding a Node to the Nodes Collection of the TreeView itself in your code.
Have you verified that your code to build the TreeView works on a small XML dataset ?
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
Hi All,
I have a column in my table which contains a string that can have data like below:
ABC 1
ABC 10
ABC 2
ABC 100
ADBCDEF - 1
ADBCDEF - 10
ADBCDEF - 3
I need the output to be like:
ABC 1
ABC 2
ABC 10
ABC 100
ADBCDEF - 1
ADBCDEF - 3
ADBCDEF - 10
When i apply dataview.sort, it gives output as:
ABC 1
ABC 10
ABC 100
ABC 2
I need to sort my datagrid with the above column.
Can anyone provide a sorting algorithm to solve this.
Thanks
Sai
|
|
|
|
|
Tricky case.
I would split the numerical part and text part, but keep them in one class.
* Then you can order by the text first and with the numeric part second through a custom function implementing some sorting algorithm.
* or group first by text and with an array of integer attached to them like "ABC" with { 1, 2, 10, 100 } eg. Then you can order the class with the text property and print the concatenated text/integer ordered by the numerical part.
* If they can stay split in the dataview you could just do like in a database´s order by clause, simplifying things a bit.
Hope this helps.
|
|
|
|
|
It depends. In the general case, that's called Natural Sort, which isn't one specific algorithm but a family of different ways to compare strings such that their order looks "natural". That's an inherently ambiguous requirement, so there are many different implementations. It gets particularly difficult if you want to include dates.
If it's just about strings that end in some number of digits, there is an easy ad-hoc solution for that.
|
|
|
|
|