|
Hi all,
I'm working on a method that parses through a html source file, and puts coldfusion comments around script tags. My problem is that the String.Input method is not working with the line read from my streamreader. When using the debugger, it hits the .Input(index, string) line, but it does actually change my string. I think this is because the line is in a stream, but I'm not sure. I know there is a programmatically simple workaround for this, but I haven't done it in so long that I can't remember. Suggestions please - my code is as follows:
private void outputnoscript(StreamReader reader, StreamWriter writer)
{
string line = "";
int opencounter = 0;
int closecounter = 0;
while(line!=null)
{
line = reader.ReadLine();
if (line!=null)
{
MatchCollection opencollection = Regex.Matches(line, "<script",RegexOptions.IgnoreCase);
for (int i = 0; i < opencollection.Count; i++)
{
Match openmatch = opencollection[i];
line.Insert(openmatch.Index + opencounter, "<!---");
opencounter += 5;
}
MatchCollection closecollection = Regex.Matches(line, "/script>", RegexOptions.IgnoreCase);
for (int i = 0; i < closecollection.Count; i++)
{
Match closematch = closecollection[i];
line.Insert(closematch.Index + 8 + closecounter, "--->");
closecounter += 4;
}
writer.WriteLine(line);
}
}
}
|
|
|
|
|
There is no Input member of the String class, but looking at your code I assume you mean Insert .
Strings are immutable. Performing an operation on a string does not change the string itself, but changes a copy of the string and returns it. So, either use something like string s = line.Insert(...) and write that using writer.WriteLine , or use a StringBuilder which is a mutable string.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is it just me or did Microsoft leave out a nice feature like allowing datagrid hyperlink columns for Windows Forms projects??? It's easy to do in ASP........
I've looked all over for someone who has succeeded to create a dataGrid.dataColumn hyperlink. I'm not using a database, just importing a firewall.txt file and sorting the IP's looking for duplicate access attempts. The idea is to simply click on the questionable IP and jump to arin.net for a quick look, however............ help......
|
|
|
|
|
Actually, MS left out more than hyperlinks in their datagrids.
What you can do, is derive a hyperlink column class from the DataGridTextBoxColumn and put a hyperlink control in it, override some events and voila, you have yourself a hyperlink column.
Here's an example on how to create a combobox column[^]. Just substitute it with a hyperlink control.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
|
|
|
|
|
Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH..
I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?
|
|
|
|
|
If you're just wanting to monitor mouse messages for a short period of time (such as for a popup/menu), you can set the form's Capture property to true . This will redirect all mouse messages to your window. After the first click outside of your window, the mouse capture will be released and you won't get any more mouse messages from outside your form.
Other windows, including child windows on your form, will not recieve any mouse messages while your form has the mouse capture. If you need child windows to recieve mouse messages, release the capture when the mouse moves within your form's bounds.
Note that it is bad practice to capture the mouse for more than just a brief period/operation, as the mouse pointer is a shared system resource.
"A people that values its privileges above its principles soon loses both." -- Dwight D. Eisenhower
|
|
|
|
|
Well, a maybe simpler way could be to add an event handler for the Leave or Deactivate event.
The moment the user clicks outside your form it's losing focus and this event can be caught and handled.
But you have to remember that when you close the form yourself then these events are generated as well IIRC.
And that switching the window by using Alt-TAB for example also triggers this event, not just mouse clicks.
Regards,
mav
|
|
|
|
|
At least you have a decent user name
|
|
|
|
|
When my screensaver is running, I want to wake it up after a short period of time,
how can I do that?
Thanks..
|
|
|
|
|
If your application uses a message queue (i.e., a Windows Forms application), you can use SendKeys.Send("+") , otherwise use SendKeys.SendWait("+") (which you could also use in a Windows Forms application if you'd like). This sends a message for the SHIFT key, a safe key to wake-up the machine (and stop the screensaver, unless the particular screensaver doesn't simply quit with certain key strokes or mouse movement).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
After your Timer has run, call this.Close(); . Your question is rather open ended however you will simply need to end the execution.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Ok got a big problem. I have a brand new machine..i.e I rebuilt it and now I want to run a web project that references some C++ assemblies and some C# assemblies. I have done everything by the book but I keep getting the same error:
Parser Error Message: File or assembly name Core.Data.TM1, or one of its dependencies, was not found.
With the trace as follows:
=== Pre-bind state information ===
LOG: DisplayName = Core.Data.TM1
(Partial)
LOG: Appbase = file:///c:/inetpub/wwwroot/TMJTester
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
===
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: Core.Data.TM1
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/tmjtester/51fb5434/c4dfe5c7/Core.Data.TM1.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/tmjtester/51fb5434/c4dfe5c7/Core.Data.TM1/Core.Data.TM1.DLL.
LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/TMJTester/bin/Core.Data.TM1.DLL.
LOG: Publisher policy file is not found.
LOG: No redirect found in host configuration file (C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet.config).
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config.
LOG: Post-policy reference: Core.Data.TM1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4c3e63d723dc8458
___________________________________________________________
this seems like it is a circular reference issue...cannot be sure though. Any suggestions on how to figure out where the problem might be ?
Thanks
Sameer
|
|
|
|
|
sameer handa wrote:
I have done everything by the book but I keep getting the same error
And what book is that? Make sure that your assemblies are strongly named, and it's best to intall them into the GAC. There are known problems with using signed files in the private path (bin sub-directory by default for ASP.NET). The .NET service pack documentation claims this is by design, however.
If you need additional help, please be specific about how you have set up your ASP.NET Web Application. I.e., where are your assemblies (remember that the PATH environment variable matters not) and are they strongly named?
The fusion log above just states that an assembly cannot be found so it is searching for redirects and in common locations. All that means is that the assembly cannot be found.
Believe - when developed and deployed correctly (i.e., typically into the GAC) .NET assemblies do end DLL hell. I recommend you read the section How the Runtime Locates Assemblies[^] in the .NET Framework SDK - the only "book" I ever follow.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks in part to your verbal smackdown I was inspired to read the SDK last night. Sometimes...reading the big C# book is not the same as reading the SDK.
Anyway I think I am close to finding the problem.....The problem is that in the Temporary ASP.NET Files directory there is a file being created called
__AssemblyInfo__.ini which has "wrong" information i.e it has the wrong
PublicKeyToken=4c3e63d723dc8458. Not quite sure where it is getting this information and I say this simply because it is my 3rd day here and I am not that familar with the code and set up yet.
So if yuo have any ideas on where I could start may be good.
|
|
|
|
|
I'm sorry you view it as a "verbal smackdown" - it wasn't intended as such.
Make sure the correct assembly is installed into the GAC. If your putting signed assemblies into the bin sub-directory (it works, but you may have problems when the AppDomain is recreated due to changes in the web application). This is done for you automatically if you add references to other assemblies (besides those already in the GAC, or those with "Copy Local" set to "True") or projects in your solution.
I also recommend you shutdown the web site(s), clear the Temporary ASP.NET Files" directory, and restart the web site(s). This should recreate all information once you have everything in place correctly as I described above.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have 2 questions, and answering either will easily solve a problem.
The first, where might I find the lovely bitmaps and such that Microsoft uses in their operating system so that I can use these same ones in my application? Particularly, the arrow button that you see at the ends of slider bars and combo boxes.
~OR~
If I have a combobox with nothing in its list, and I click the dropdown button, how can I prevent the list from showing one blank line?
Either answer will help! Thanks a bunch.
- D
|
|
|
|
|
See the ControlPaint.DrawComboButton method in the .NET Framework SDK for one option. Otherwise, you'll need to include bitmaps yourself, either embedding them into a ResX file (using an ImageList in the designer does this for you, which base64-encodes it) or embed them as manifest resources by adding them to your project and changing the build action to "Embedded Resource". You can access these bitmaps (which I use generically for pixel map images) using Assembly.GetManifestResourceStream or some methods on the Image and Bitmap classes allow you to specify a manifest resource from which an Image or Bitmap (derivative of Image ) is created.
It's important to understand that most of the Windows Forms controls are not implement in .NET, per se. They encapsulate the Windows Common Controls, so it's the native window classes that are being used and which take care of drawing themselves (for the most part).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I like the ControlPaint.DrawComboButton method, however, why doesn't the OnPaint handler fire in a class inherited from a TextBox?
If I change the base class to Label, or another control, the OnPaint handler fires, but not with TextBox...any ideas?
|
|
|
|
|
It's not supposed to fire. As I've tried to remind those in this forum many times, most of the Windows Forms controls encapsulate the Windows Common Controls. The TextBox encapsulates (wraps) the Edit control, which paints itself and cannot be overridden as many other controls can (like the Static class, which is encapsulated in the Label class). Even the ListView doesn't work the same with the call to OnPaint . In order to custom draw items, you have to handle the right notification messages.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Has anyone experienced a problem with SHDocVw in C# where the events don't fire? This problem seems to be random as on some computers they do fire and some they don’t.
I'm not trying to use create a browser control, so I’m not using axSHDocVw.
What I’m trying to do is automate tasks between 2 IE windows e.g. cut & paste.
Any help would be appreciated.
Thanks
|
|
|
|
|
|
Thanks for the ref to that article.
How do you create a generic handler for the SHDocVw.InternetExplorer?
|
|
|
|
|
|
Not through the BCL, no. You can P/Invoke InternetGetCookie :
[DllImport("wininet.dll", CharSet=CharSet.Auto)]
private static extern bool InternetGetCookie(
string url,
string cookieName,
[Out] string cookieData,
ref int dataSize); That third parameter should not use out , mind you - it should be marshaled as an [out] param using the OutAttribute only, otherwise the CLR will crash. See the Platform SDK for usage, but it's really pretty easy to do. To easily allocate a string of a certain size, you can use new string('\0', size) or declare those as StringBuilder s and modify your source accordingly.
Then you can parse and include these in your CookieContainer for use with the HttpWebRequest .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was wondering if there is way for me to set current input language using C# (not Windows settings)... for instance whenever user focues my form I want to set current language to, let's say Spanish.
Anyone can help?
And... yes; I presume that languages are installed but it would be good if in response would be included a hint to where can I see how to detect currently installed languages on computer and do little validation.
Tnx
|
|
|
|