Images and Parameters Broken in CrystalReportViewer

2009 May 28
by echostorm

 

I hate Crystal Reports.  I was on the verge of a nervous breakdown today after launching a well tested app and finding my reportviewer with broken images or with a mysterious javascript error saying Object Expected.

CropperCapture[2]

The deal is that Crystal requires the aspnet_client folder that IIS creates in your Default Web Site and is accessable to all the virtual folders that live there.

However if you try to deploy your site to a new website on the server to use a different port or subdomain using host headers you won’t have access to the aspnet_client goodness and your reports will be borked.

 CropperCapture[1]

You can either copy the folder into your application folder or create a virtual folder that points to the aspnet_client folder in the Default site.

CropperCapture[4]

and you’re golden.

CropperCapture[3]

I owe a co-worker with a good memory for putting me on the right scent to figure this out.  Hope this helps someone avoid the anguish this caused me.

Save User Data In Silverlight

2009 May 20
by echostorm

So I’m writing a little time wasting game that step-father 2.0 came up with.  It’s a sort of sudokuesque columns blend.  Of course we want to have a way to keep track of your top ten scores for bragging rights. 

Anyway, in Silverlight you get, to start out, ten megs of isolated storage on each user’s drive to work with.  You can prompt them for more space if you like but for our purposes we’ve got plenty of room for a little text file to store the top ten scores.   private

void SaveScore() {

List<double> scores = new List<double>();

string rawScores = LoadData(“scores.dat”);

/* If there are scores, read them in */

if(rawScores.Length > 0) {

string[] splitScores = rawScores.Split(‘;’);

scores = splitScores.Select(a => double.Parse(a)).ToList();

}

scores.Add(score);

/* Get the scores in order highest to lowest */

scores.Sort((a,b) => b.CompareTo(a));

/* Take the new top ten and semicolon delimit them */

string newScores =

scores.Take(10).Aggregate(“”, (a,b) => (a + “;” + b)).TrimStart(‘;’);

SaveData(newScores, “scores.dat”);

}

And the supporting methods..

private

 

void SaveData(string data, string fileName) {

using (IsolatedStorageFile isf =

IsolatedStorageFile.GetUserStoreForApplication()) {

using (IsolatedStorageFileStream isfs =

new IsolatedStorageFileStream(fileName, FileMode.Create, isf)) {

using (StreamWriter sw = new StreamWriter(isfs)) {

sw.Write(data);

sw.Close();

}}}}

private

 

string LoadData(string fileName) {

string data = String.Empty;

using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) {

using (IsolatedStorageFileStream isfs =

new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, isf)) {

using (StreamReader sr = new StreamReader(isfs)) {

string lineOfData = String.Empty;

while ((lineOfData = sr.ReadLine()) != null)

data += lineOfData;

}}}

return data;

}

Empty Option in DropDownList Bound to LinqDataSource

2009 April 2
by echostorm

This has been driving me a little crazy.  Sure if it was a completely code side binding I could insert the empty row into the datasource myself but I’m doing lots of work in ListViews of late so that option is totally out.  I ended up finding the answer on StackOverflow.

<asp:DropDownList ID="ddlEditEmployee" AppendDataBoundItems="true"

runat="server"

DataTextField="Value" DataValueField="ID"

SelectedValue='<%# Bind("EmployeeID") %>'

DataSourceID="LinqDataSource2">

<asp:ListItem Value="-1">

None

</asp:ListItem>

</asp:DropDownList>

The AppendDataBoundItems bit is important too otherwise sneaking that default on in there is for nothing. Enjoy.

Clean Complex Databinding in ASP.Net

2009 April 2
by echostorm

So I needed to do a little CRUD ListView for a simple app I’m working on.  One of the columns is an image path that I was using an Image object to display.  The object got vetoed and I’m going with text now so I wanted a clean way to either show a simple text link to pop the image on a new tab or show that no image was available.  I went with this in the template:

<td><%# GenerateImageField(Eval("ImagePath")) %> </td>

 

public string GenerateImageField(object dataItem){
if (dataItem == null || string.IsNullOrEmpty(dataItem.ToString()))
{
return "No Image";
}
return @"<a href='"+ dataItem.ToString() +@"' target='_blank'>Image</a>";
}

This works out rather well.

croppercapture1

ASP.Net Server Control Tag For QueryString

2009 March 26
by echostorm

Maybe I’m just lucky but I’ve only had to use control tags in ASP.Net apps very infrequently and I always forget how they work until I need them again.  Sherlock Holmes would say thats a good thing but I’m going to post a little example here for my own benefit. 

I LOVE the ListView control that we got in 3.5 and I’m using it alot in the dinky apps I’m banging out of late.  For this one I needed to create a little link in the grid for each row using the current querystring and the row’s ID.

<

asp:ListView ID=”lvLicenses” runat=”server” DataSourceID=”dsEmployeeLicense”>

<ItemTemplate>

<tr style=”background-color: #E0FFFF;color: #333333;“>

<td>

<a href=’EmployeeLicense.aspx?EmpID=<%=Request.QueryString["ID"]%>&ID=<%# Eval(”ID”) %> target=”_self”>Edit</a>

</td>

Easy as pie.  mmm pie.