smithvoice.com
Pages by tag

17 pages are tagged with CSharp


To check more tags, click here  click to open


Redirected Downloads


Summary:

We have files for download on a NAS.  We don't want to expose them directly to everyone hitting the site and the idea of just mapping the drives makes people go nutty so, got a fast idea?  We know that by this time it's got to be so simple that we're missing the obvious but we're going in circles and a vendor wants too much money for a bridge product.

Huh.  Does the file server run IIS or Apache/Mono?

It's a Windows server so IIS is ok but we don't want to expose it to the internet.

You don't have to, if it's on your company network just expose it internally so the web servers can hit it.  That possible?

The answer is going to slay you... open up notepad and copy this in:



Regex Ajax Jquery UserControl


Summary:

This universe is fun.  Last week I was having a conversation with a budd about a validation regex and just a few days later I had the need to dig it out for myself ... lucky I put it on the sitelett (thanks Universe!).

In my case I needed to make a double listbox picker for Keywords.  Over the years I've just used Telerik controls but this is a lean webapp and I didn't want the extra baggage so I rolled my own.  ASCX with serverside needs plus Jquery/JS Ajax hitting an ASMX web service for adding new keywords on the fly without page reloads.

Demo here.  Code and some notes ...[more]



Simple person name regex


Summary:

"Do you have a good regex to test a person name part entry?"

Yep.  ^[A-Za-z]+((-[A-Za-z]+)|('[A-Za-z]+)|(\040[A-Za-z]+))*$



Hack the Profile Provider


Summary:

So you don't want to reinvent the wheel on an ASP.Net profile system but you need to support some perfectly understandable business rules for the profile data that the precooked Profile Provider doesn't handle well?

You just create a custom Profile Provider to hold your props in a custom table instead of that silly serial format, right? 

Yeah... but what if one of those rules requires a lookup validation and message to the user?  Your custom implemented Save() has to return void,  a status code won't work and a custom exception from SetPropertyValues will choke your web site.

Well, there's a hack for that.



Webforms Inherited Panel control


Summary:

Wasn't going to post this because some magic made the original problem go away, but just in case it comes back... my sitelett search makes it easier to find stuff than searching for commented out code :-).

Needed a container control for a Repeater's ItemTemplate so users could get the info from any collection of display controls (labels, images, whatever) and just click anywhere in the set for a serverside event instead of putting a button into the mix.

Easy enough, added an inherited Panel.  Worked fine as a drop-in on test pages but when added to the Repeater and was inline bound the doPostback javascript errored out on registration.  It was being rendered correctly in the html but when used in an ItemTemplate it didn't want to even get past page_load.

So I hand-wired the Render method to use the settimeout style and poof, it worked as a list item container.



ASP.Net limited textarea for Ajax


Summary:

Huh?  What?

Oh sorry, been heads down the past few ... months?  Sheesh.

Ok.  There is one thing I did the other day that I'll forget if I don't put it here.  I'm working on a few new sites and all of them at one place or another need a textarea with a character limit.

I know, we've all done these since before the beginning in one way or another.  It's no big deal to just check the length  in the postback or add a key event javascript method with an alert or whatever, and these days even adding a countdown span means just grabbing someone's freebie jquery sample. 

Those all work fine mostly.  But for this project there was a twist that threw me a fail...



Serialization Error on hosted site


Summary:

"I'm using an add-in architecture for a webforms project like the ones you used to talk about, based on Rocky's CSLA for validation but not his overhead.  As usual everything is fine on my machine and our test server but when I drop it on a hosting company server I get 'System.Security.Permissions.ReflectionPermission' when I'm doing the clone of any data objects.  I like the system (old school!) but can you suggest a fast reason for this error?"

Ah Medium trust.

I take it you're using the DataContract attributes for the serialization?  If so, maybe you went the extra mile (as we all do) and implementated IExtensibleDataObject... even if you don't really have a reason to do any roundtripping of data.  If you are and if you don't need the feature just try dropping the implementation. 

If you DO need the roundtripping ...



Winform Designmode


Summary:

Coding out and about without my libraries drive and hit that old, old, old bug of user controls not making it easy to tell you when you're in Designmode if you nest subclassed UCs. Felt like a noob fool, had to waste time running through all of the forum posts of hacks that still don't work.. till I found this one. It's not mine but it's better than mine in that it works (for me) across the nesting scenarios even when called from a grandchild control. Now I'm glad I forgot my drive :).

The code is in an Anonymous comment, in case that page goes away, I put it here.

Why does the simple DesignMode feature that was spot-on in the VB5/6 era still elude the VS team after ten years of .Net? 

Thanks Anonymous!



Get back the explicit prop


Summary:

Here's one of those things that some of us came cross way back and fixed on our machines and promptly forgot about, but that comes up every time you hit a new machine or machine from a new .Net convert.

A few days ago I told a friend how he could get a few performance gains by modifying the wizarded Entity classes and when I went to his house and sat at his 'puter my fingers called up the prop snippet and got that VS2008 shortie:

public int myProp{ get; set;} 

Ugh, I hate that thing. 

I know that "under the hood" C# creates a hidden variable for that syntax-saccharine shorthand but it gets me that back in the day of VB5/6 when the tool created ANYTHING under the hood all we ever heard from C++ guys was that that practice was shining example of why VB sucked... nothing should be "under the hood."



A couple useful VS Snippets


Summary:

coming from a decade of VB, "msgBox" is what my fingers keep typing whenever I want a dialog. It's so much faster and natural for me than "M..e..s..s..a..g..e..B..o..x. [tab]S..h..[tab]".

There is a C# snippet to save the typing, it's "mbox", yeah that's shorter, but my fingers still go right to the "g" instead of the "b". Thanks to how easy it is to make a snippet this is no longer a problem....

Here's another one that comes in handy: A tweaked class snippet.

80% of the time my classes get refactored into the same regions, "declarations", "public properties", "private property puts" (for internal business rule checking, keeping ...



<< 1 2 >> 
who is smith     contact smith     rss feed
Since 1997 a place for my stuff, and it if helps you too then all the better smithvoice.com