home · blog · groups · about us · contact us
DevelopmentNow Blog
 Friday, March 28, 2008
 
 

So you can probably tell that I've been doing a lot of LINQ lately. :) One thing I've found is that it's easier for me to write complex queries in the database as stored procedures or views, and then use Linq to SQL to retrieve the results, sort, filter, do paging, etc.

The downside of that approach is the results normally come back as a <view or proc name>Result type, instead of the actual table type. That's sometimes an issue, because I use partial classes to give my table classes some extra functionality, and I might want to allow updates, etc. against various tables.

So the goal is to be able to call a view or stored procedure, but coerce those results into a good ol' MyTable object.

You may already know how you can drag a stored procedure or view from your database (in Server Explorer), and drop it on top of a Table entity in the O/R designer. That will cause the stored procedure to return results of that table's type, instead of <procname>Result.

But Rick Strahl had a great post from a while back explaining how you can use views, procs, & dynamic SQL, and cast those results to a specific table type using ExecuteQuery. A snippet from Rick's post is below:

What's also interesting is that when you provide LINQ a query like this it still works with the DataContext's change tracking. For example, the following code actually works as you'd expect:

IEnumerable<Customer> custList =  context11.ExecuteQuery<Customer>("select * from Customers where CustomerId={0}", "ALFKI");
Customer cust11 = custList.Single<Customer>();
Response.Write(cust11.CompanyName); 
cust11.CompanyName = "Alfreds Futterkiste " + DateTime.Now.ToString();
context11.SubmitChanges(); 

custList = context11.ExecuteQuery<Customer>("select * from Customers where CustomerId={0}", "ALFKI");
cust11 = custList.Single<Customer>();
Response.Write(cust11.CompanyName);

The cool thing (as Rick mentions) is that you don't have to do a "select * from Customers" -- you could do a "select CompanyName, ContactName from Customers" and it will work, too. You don't need to bring back all columns in order to successfully cast the result to a Customer object.

I'll post my continuing forays into Linq as I continue. One thing that remains to be seen is whether Linq to SQL is robust enough to be helpful vs requiring me to extend it too much to do what I want/need.

March 28, 2008    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Thursday, March 27, 2008
 
 

I wanted to put up a few examples of SQL vs Linq to SQL for my future reference, since we're using it in one of our social media projects for artists. I'm pretty handy at SQL, but it doesn't translate exactly to Linq to SQL.

Example 1

Assume you have a view called vev_bws_mediaVoteDownloadHistory that votes and downloads for different media by date. So it contains columns like mediaId, artistId, activityDate, votes, and downloads.

If we wanted to query this view to get the total number of votes and downloads for a given media, you could use SQL like this

SELECT 
    votes = SUM(votes),
    downloads = SUM(downloads)
FROM vev_bws_mediaVoteDownloadHistory WHERE mediaId = 12345

Or use Linq to SQL like this

veDataContext dc = new veDataContext();

var totals = (from v in dc.vev_bws_mediaVoteDownloadHistories
              where v.mediaId.Equals(12345)
              group v by v.mediaId into h
              select new
              {
                  votes = h.Sum(x => x.votes),
                  downloads = h.Sum(x => x.downloads)
              }).FirstOrDefault();
if (totals == null) then return; // no totals

Response.Write(totals.downloads);
Response.Write(totals.votes);

Example 2

So the first example was jsut getting a few simple sums. Here's a bit more complex example.

Assume you have a view called vev_bws_userMediaHistory that logs votes for a given artist and his/her media. The view fields like votes, artistName, mediaName, userId (the user who cast the vote), and voteDate (a datetime column storing the date & time of a vote).

So since voteDate contains dates and times, I want to display all the votes grouped by media, artist, and date (not time). I could use SQL like this:

SELECT 
    votesperday = SUM(votes), 
    date = CAST(FLOOR(CAST(voteDate as FLOAT)) AS DATETIME),
    mediaName,
    artistName
FROM vev_bws_userMediaHistory
WHERE userId=1
GROUP BY 
    CAST(FLOOR(CAST(voteDate as FLOAT)) AS DATETIME),
    mediaName,
    artistName
ORDER BY CAST(FLOOR(CAST(voteDate as FLOAT)) AS DATETIME) DESC

Note that the CAST/FLOOR/CAST trick is used to trim off the time from a datetime, leaving just the date portion. This allows us to sum up votes cast throughout the day into a "votes per day" value.

To do this in Linq to SQL I would use this:

veDataContext dc = new veDataContext();

var votes = (from v in dc.vev_bws_userMediaHistories
             where v.userId.Equals(1)
             group v by new 
             { 
                 v.voteDate.Date, 
                 v.artistName, 
                 v.mediaName
             } 
             into h
             orderby h.Key.Date descending
             select new
             {
                 date = h.Key.Date,
                 artistName = h.Key.artistName,
                 mediaName = h.Key.mediaName,
                 votesperday = h.Sum(x => x.votes)
             });

The above Linq select statement allows me to reference the artistName in my ListView via <%# Eval("artistName") %>. If I had instead used this select statement

select new
{
    h.Key,
    votesperday = h.Sum(x => x.votes)
}

I would need to use something like <%# Eval("Key.artistName") %> instead.

March 27, 2008    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 
 

FYI, there's a bug in the RTM LinqDataSource where child tables aren't loaded unless you have updating or deleting enabled. Apparently if you have a LinqDataSource that doesn't have updates or deleted enabled, ObjectTracking is turned off (for performance reason), but deferred queries (e.g. queries to pull back child rows) aren't executed.

So statements like

<%# Eval("ChildTable.ChildTableField") %>

in your ListView, etc. won't work.

Annoying, needless to say. But at least now I know.

So, there are a few options:

  1. Set EnableUpdate="true", which will enable ObjectTracking and cause deferred updates to work
  2. Add a SELECT statement in your LinqDataSource (e.g. SELECT="new (field1, field2, childTable)") to pull back everything you need.
  3. Handle the ContextCreated event to either manually set ObjectTrackingEnabled, or manually set LoadOptions.
public void OnContextCreated(object sender, LinqDataSourceContextEventArgs e) {
  ((DataContext)e.ObjectInstance).ObjectTrackingEnabled = true;
} 

OR 

public void OnContextCreated(object sender, LinqDataSourceContextEventArgs e) {
    var dataLoadOptions = new DataLoadOptions();
    dataLoadOptions.LoadWith<MyTable>(t => t.ChildTable);
    ((DataContext)e.ObjectInstance).LoadOptions = dataLoadOptions;
}

Setting LoadOptions is normally the best approach for performance.

March 27, 2008    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Sunday, February 24, 2008
 
 

SubText - http://www.subtextproject.com/

BlogEngine - http://www.asp.net/downloads/starter-kits/blog-engine/

dasBlog - http://www.dasblog.info/

FYI we use dasBlog here, but SubText & BlogEngine look interesting ...

February 24, 2008    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Wednesday, July 18, 2007
 
 

SubSonic is an open source project loosely modeled after Rails. It uses BuildProviders to automatically generate the DAL/ORM code at compile time, meaning you don't have to manually regenerate code every time your database schema changes.

The downside was that the code was only auto-generated for Web Site projects, not Web Application or Class Library projects. So Rob Conery has a recent post about using Pre-build Steps to autogenerate the SubSonic code for all types of projects.

So, read the "What will it do for me?" on the SubSonic home page, and check out the first 5-10 minutes of a recent screencast. If you like what you see, maybe try it out in your projects.

If you aren't already using DALs and code generation to accelerate your development work, you really owe it to yourself to check it out. :)

July 18, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Friday, March 23, 2007
 
 

This was inspired by a form post over in startupping, where people were discussing doing projects in ASP.NET or PHP (specifically, LAMP: Linux, Apache, MySQL, and PHP).

I do both ASP.NET (.NET 2.0, C#, SQL Server) & PHP development (LAMP). PHP is pretty easy to pick up (especially if you've programmed in classic ASP), and there's a lot of information, libraries, etc. out for it. For an IDE you could use Zend Studio ($99-$300), PHP Designer ($50+), or free ones like SciTE or PSPad (both are good).

If you just want to try out some PHP development, I'd suggest getting a cheap hosting account from GoDaddy, Dreamhost, or somewhere else. Or even e-rice.net ($10/year). While you could install Linux locally & play around with shell access & administering Linux, Apache, MySQL, and PHP, you could end up spending a lot of time being a Linux sysadmin -- time that you could have instead spent strengthening your PHP & MySQL skills. One step up from a cheap hosting account would be to run LAMP as a virtual machine by downloading the free VM player and ready-to-go LAMP packages.

Once you get beyond coding some basic stuff, you may want to look into better PHP frameworks to help accelerate your development. I like Code Igniter, but here's a list of other frameworks you can read about.

FWIW, I develop in both environments b/c I have a range of clients & projects w/ different needs. One of my current projects is a site that includes a lot of features (social networking, wiki, CMS, data management), but the client wanted to leverage existing open source libraries & avoid building everything from scratch. So LAMP was a natural way to go. Other clients are Microsoft shops, so they want .NET apps built that their existing IT staff can take over.

Like any project, I think deciding on a technology involves many factors -- how skilled are you in it? Do you want to learn a new technology? What does the technology cost? Are there things about this technology (language features, environmental features, pre-existing libraries & applications) that will help the project to be more successful?

Lastly, if it's costs that you're concerned about, IMO Microsoft projects aren't as expensive as some may think. You don't need to spend a lot of money on the IDE -- there are cheap or free IDEs you can develop in, or (if you qualify) you can enroll in the MS Empower for ISVs program for $375, which gets you an MSDN Universal license w/ OSes & dev tools. The .NET framework is free, and you can run IIS on XP Pro. SQL Server Express is free & has (almost) all the features that you'd be using in SQL Server Workgroup/Standard/Enterprise. I have a client that didn't have a very large database, so their production site runs on SQL Express.

Also, if you're using a hosting provider for your site (which you usually should), choosing a Windows OS & SQL Server for your hosting account isn't usually significantly more expensive than Linux.

Still, obviously LAMP is cheaper (free, unless you pay $$ for a better IDE), and Microsoft costs can add up if you're looking at big server farms or are buying your OS & SQL Server licenses outright (for some reason). But of course switching frameworks has its own cost in terms of time & mistakes made while learning. If I were building something simple from the ground up, I might just choose the platform I was strongest in.

March 23, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Tuesday, March 13, 2007
 
 

I've been having some issues with a hosting provider getting HTTP Compression set up correctly for ASP.NET pages in IIS. It's not hard to set up, but you need to do it using command line tools, not the IIS Management Tool. Thus it's probably not well-known, and possibly viewed as an unsupported hack by some hosting companies.

Believe me, when you're working with a hosting provider, you don't really want to do too much stuff that they don't support. Otherwise, if anything goes wrong, they'll say "well, of course you're having problems, it's probably because you're doing that crazy unsupported stuff."

So I was worried that I'd never get HTTP Compression running for this ASP.NET site, when today I ran across this HTTP Compression module from Ben Lowery that you can literally drop into your bin directory, add a few things to your web.config, and shazam! your ASP.NET pages are compressed. Now that's frickin awesome. And it's free & open source. And it seems to work.

So...if you have an ASP.NET site that you'd like to try compressing, and you either can't or won't configure compression in IIS, give Ben's module a try. Note that compression uses up CPU, so if you're using shared hosting, you should probably use the deflate algorithm on the low setting to minimize the CPU usage. And even that might be too much CPU utilization -- you'll have to see.

Also one thing I noticed ... the high/medium/low compression settings only affect deflate, not gzip. :/

Edit: well, looks like it's somehow corrupting the AJAX return calls in Anthem. Or, trimming out most of the JSON. Or something. Anyhow, the non-AJAX pages seems to work pretty well, but I'll test it a bit further. I like how to can specify URLs & mime types to not compress, although the ability to provide a regex to skip compression on would be nice.

March 13, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [1]



 Wednesday, February 28, 2007
 
 

Ok ok, you want to compress your ASPX files in IIS, but you don't want to do it for every site, and you want to exclude certain directories. You don't want to edit the metabase by hand, either.

No problem! Copy the below into a BAT file, run it from a command prompt, and voila! Note that you should edit the site number and directory numbers.

But before you run the below BAT, back up your metabase and make sure you know how to restore it! IIS Manager->Right-click server->Tasks -> Backup/Restore Configuration.

If you don't feel comfortable administering IIS or running the below batch file, don't! And even though I hate disclaimers, this script is provided AS-IS with no warranty in any way.

REM HTTP Compression Script
REM
REM Enables compression of static and dynamic files
REM Turns off compression for all sites except site #123
REM Also turns off compression for site #123's /SomeDirectory/Directory2 directory
REM
REM Copyright 2007 Ben Strackany
REM This script is provided AS-IS, no warranty implied or provided, Ben Strackany and 
REM DevelopmentNow are not responsible for any damage your site, server, or love life 
REM may incur as a result of running this batch file.
REM
REM BACK UP YOUR METABASE BEFORE RUNNING THIS SCRIPT!

REM compress static files
CSCRIPT.EXE C:\Inetpub\AdminScripts\ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "js" "txt" 
CSCRIPT.EXE C:\Inetpub\AdminScripts\ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "js" "txt"

REM compress dynamic files
CSCRIPT.EXE C:\Inetpub\AdminScripts\ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "asmx" "aspx"
CSCRIPT.EXE C:\Inetpub\AdminScripts\ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "asmx" "aspx"

REM set compression level
CSCRIPT.EXE C:\Inetpub\AdminScripts\ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel "9" 
CSCRIPT.EXE C:\Inetpub\AdminScripts\ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcDynamicCompressionLevel "9"


REM turn off global compression
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/root/DoStaticCompression False 
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/root/DoDynamicCompression False 

REM turn on compression for a specific site
REM ****** EDIT THE NUMBER TO BE THE SITE # YOU WANT TO TURN COMPRESSION ON FOR ****
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/123/root/DoStaticCompression True 
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/123/root/DoDynamicCompression True

REM turn off compression for a given dir
REM note that the dir needs to exist in the metabase: in IIS, create the vdir, then optionally
REM open properties for it and click "Remove" next to the application
REM ****** EDIT THE NUMBER AND DIRECTORY TO BE THE SITE AND DIRECTORY YOU WANT TO TURN COMPRESSION OFF FOR ****
cscript.exe c:\inetpub\adminscripts\adsutil.vbs set w3svc/123/root/SomeDirectory/Directory2/DoStaticCompression false
cscript.exe c:\inetpub\adminscripts\adsutil.vbs set w3svc/123/root/SomeDirectory/Directory2/DoDynamicCompression false

REM restart IIS
iisreset.exe

 

The above is pretty self-explanatory. In the top half, we're setting which file types should be compressed, along with the compression level. In the bottom half, we're adjusting compression settings globally, for various sites, and for a specific directory.

The script is not only to use, but to help you understand how the HTTP Compression configuration works, so you can adjust it to suit. For example, you can include other extensions to compress (CFM, PHP), or turn on & off compression for other webs, directories, or files.

To test your settings, get yourself a copy of Fiddler and install it. Run Fiddler, and browse your site. In the left pane, click a request that you think should be compressed, then click the Session Inspector tab on the right and look in the HTTP Compression area. If your page is compressed, GZIP or DEFLATE Encoding will be selected.

fiddlergzip.png

Thanks go to posts from BlueDog, KB234497, and Scott Forsyth.

ASP.NET | OS
February 28, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [2]



 Tuesday, January 30, 2007
 
 

I was looking at wikis recently and thought I'd list out the ASP.NET wiki's I've noticed. Obviously there could be more, but here are the one's I've seen:

  • FlexWiki -- been around for a while, easy to install & use.
  • ScrewTurn -- has gotten some good buzz recently, seems the most active recently w/ a number of interesting features.
  • Perspective -- I recently noticed this. Has a WYSIWYG editor (which I think is good for corporate adoption). You can also attach & embed files (e.g. Microsoft Office Docs) & images, & search across them. Seems like it might be complicated to set up & install.

I believe they all can do authentication/authorization through NTFS and/or LDAP, so you can administer the permissions like you would any other IIS web site.

Here is a WikiMatrix comparison page of the above three wikis, although I don't believe their information is completely current.

January 30, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Tuesday, January 23, 2007
 
 

Smashing Magazine came up with a link-list post called 53 CSS Techniques You Couldn't Live Without. It links to cool CSS effects that are easy enough to add to your web applications. Developers (like me) are notorious for being, hmm, spartan when it comes to design, so ready-to-go script that lets me jazz up my pages is welcome. Plus, Smashing included little screenshots of the effects, so you don't have to click through to see what they're like (though a few of the screenshots don't really explain the effect well [I'm talking to you, Link Thumbnail]). Anyhow, here's images of a few:

CSS Teaser Box
CSS Teaser Box

CSS Ratings Selector

 

ASP.NET | Code | Web
January 23, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Sunday, January 21, 2007
 
 

I was reading TechCrunch today and noticed an article about booBox, a lightbox product that allows Amazon affiliates to incorporate cool web-2.0 "popups" with Amazon.com products into their site. I often read about startups on TechCrunch, and sometimes I think to myself "man, I wish I had thought of that" or "man, I could do something like that."

Well, today the barrier to entry was so low that I came up with a competing product in under an hour. And not only that, but I'm offering three times the options! And did I mention it was free? So I give you ... the DevelopmentNow Amazon GreyBox!

For demo and code, go here.

This is a real life example of what I was getting at in my Social Networking for Sale post -- with rapid development techniques, open source software, and the huge availability of turnkey widgets, code samples, and solutions, product development is becoming increasingly commoditized, allowing the easy output of "close enough clones." A previous employer had experience with a competitor whose product was "close enough" to be a real competitive threat, and so winning clients was less about the actual product than the strength of the team, marketing, PR, customer service, existing client list, and sales power.

So do I think that I'll be a serious competitor for booBox? Probably not, unless I put together a hip-looking web site, send out press releases, work the conferences, etc. And competing with them wasn't really the point. Rather, since Mike Arrington gave booBox "an early thumbs up" and said it "may be quick acquisition bait for Amazon or eBay," it seems there's potential gold even for quickly-developed apps.

Granted, I were serious (or smart?), I probably should have said my product took weeks/months to develop, not minutes/hours. And instead of using my product to prove a point on the commoditization of software in a little-read blog, I should have instead used it to go for either some web 2.0 notoriety and/or a quick-hit acquisition. But ah well. :)

booBox

booBox

DevelopmentNow's Amazon GreyBox

product link

mini link

related products

January 21, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Tuesday, January 02, 2007
 
 

I noticed a different kind of WYSIWYG editor today (credits to Brian R) called WYMeditor. It strives to provide an easy-to-use content editor for non-technical users, while keeping the formatting options to a minimum. It's actually dubbed as a WYSIWYM (what you see is what you mean) editor, and outputs XHTML for easy insertion into CMS systems. Plus, it's open source, and very lightweight. 

Their words:

WYMeditor's main concept is to leave details of the document's visual layout, and to concentrate on its structure and meaning, while trying to give the user as much comfort as possible (at least as WYSIWYG editors).

I like the idea behind WYMeditor, because it strives to avoid my beefs with many existing content editors:

  • Many common WYSIWYG editors allow too much control over the content, allow users to paste in horribly-mangled HTML from Word, etc., and/or output HTML that's laden with inline styles, extra formatting (extra breaks, tables, non-breaking spaces), and not XHTML. The content often "looks ok" in the editor, but then doesn't work out well in the site. Or, the layout can get "messed up" in the editor, but since the user doesn't look at or understand the underlying HTML, he or she isn't able to fix the formatting issue without deleting all the content and trying again. Lastly, trying to clean up the editor's HTML output & insert it into an existing page template can be tricky and leave you with a funny-looking page.
  • The other direction, using a text-only editor with special characters for formatting (like many wikis do) minimizes problematic formatting, but is less natural to non-technical users who are expecting something to "look like Microsoft Word." And I don't blame them -- Alan Cooper wrote in one of his books about how often programmers forget to design interfaces that work the way users are used or and/or expect them to, and how that can cause unexpected usability issues or other problems. Not that we should never offer anything new to users with old habits, but...well you know what I'm getting at.

However, WYMeditor is still young, barebones, & has its share of issues (no nested lists, certain browser compatibility, trouble deleting HTML tables, etc). Still, WYMeditor might be a good option now or in the future, depending on your audience and application.

 

January 2, 2007    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Friday, December 01, 2006
 
 

Scott Mitchell has a new article on 4guys about using the ASP.NET CSS Friendly Control Adapters. Using them causes standard ASP.NET controls to basically use fewer tables for layout, and instead use more lists, divs, and "proper" tags for layout & markup. The adapters also cut down on in-line styles, allowing you to keep layout in a CSS file where it belongs.

And all that means better accessibility, cleaner code, and fewer laughs of derision from your Mac-toting designer friends who say things like "Yuck, Microsoft .NET is le glos poulet laid, look at all those tables!" and then they refer you to their hipster CSS blogs. Well, look who's laughing now!

December 1, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [1]



 
 
MIT has a cool timeline widget under open source.

Unfortunately I can't really stick it inline here, but you can visit the link to check it out.
December 1, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Wednesday, November 29, 2006
 
 

Maybe you've seen some of the new cool web sites that automatically let you import people from your Outlook, Yahoo, Gmail, or other contact lists. That way your users don't have to remember or type in their friend's email addresses ... they just pick from an imported list.

Well I noticed that Plaxo has an Address Book Widget you can embed in your site that allows your site visitors to import contacts from Yahoo, etc. It would probably take you under an hour to implement on your site.

widget screenshot

FYI, the widget is free, but it contains a link to Plaxo.com.

ASP.NET | Code | Web
November 29, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Tuesday, November 28, 2006
 
 

Mads Kristensen posted an article about an HttpModule to move ViewState to the bottom of the page. It's based on Scott Hanselman's similar blog post.

The nice thing about moving ViewState to the bottom of the page is spiders don't have to sift through it, which means potentially better spidering and search engine ranking. Another benefit is that your page may render faster on browsers since more of the visible HTML is retrieved sooner.

I like the idea of making an HttpModule out of it, because then you don't have to have a custom Page class or anything .. you can just drop the HttpModule into any project & it starts working. Assuming it doesn't have huge bugs, of course. :)

November 28, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Tuesday, October 24, 2006
 
 

Google just announced Google Custom Search Engine, which allows you to create your own custom search engine and stick it on your site with a few lines of code. I was able to add one to http://www.developmentnow.com is about 5 minutes (look at the bottom of the blog page, or in the groups section e.g. at the bottom of this thread about web services).

One downside is that it relies on Google's index, so if your site isn't well indexed by Google (which mine isn't) your results are limited. But, it would be a nice thing for budding webmasters who don't want to build or maintain their own search engine, especially if they made sure to populate Google's index with Google sitemaps. And of course they make it really easy to incorporate AdSense into the search results.

October 24, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Wednesday, October 11, 2006
 
 

I was having some odd errors sending MemoryStreams as email attachments and I wasn't finding samples on the web that worked (or compiled). I was finally able to figure out that the MemoryStream needs to be open in order for the send to go through, like so:

string from = "ben@foobar.com";
string to = "you@foobar.com";
string subject = "my email";
string body = "this is an email with an attachment.";
MailMessage mail = new MailMessage(from, to, subject, body);
System.IO.MemoryStream memorystream = new System.IO.MemoryStream();
System.IO.StreamWriter streamwriter = new System.IO.StreamWriter(memorystream);
streamwriter.Write("Hello world!");
mail.Attachments.Add(new Attachment(memorystream, "test.txt", System.Net.Mime.MediaTypeNames.Text.Plain));
SmtpClient smtp = new SmtpClient();
smtp.Send(mail);
streamwriter.Close();
streamwriter.Dispose();
memorystream.Dispose();


 

If the Stream is closed you'll get a System.Net.Mail.SmtpException whose InnerException says "Cannot access a closed Stream."


October 11, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [2]



 
 

I found out today that if you have EnableViewState="False" in your master page declaration, that ViewState seemed to not be preserved for User Controls (.ascx), even if you have EnableViewState="True" in the Page and User Control's declarations.

I'm sure it's related to what Rick Strahl is talking about here but right now I'm not going to dive into it. ;)

October 11, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |