Was looking for a couple of syntactical explanations and ran across this post. Awesome.
Tricks and Tips
Just handy reference ('cause you don't always know what to google on)
Syntax
Thursday, July 18, 2013
Thursday, February 21, 2013
xml handy items
I do a lot of processing of XML documents from various sources. Just a couple of items I want to have around even through they are in my library of tricks. Removes declaration from XML document so that it can be loaded into XDocument.
private Regex M_RemoveDecl = new Regex(@"<\?xml.*?\?>");
This is to remove namespaces in documents. Makes the query of the document easier.
... Taken from this discussion
public static string RemoveAllNamespaces(string xmlDocument) { XElement xmlDocumentWithoutNs = RemoveAllNamespaces(XElement.Parse(xmlDocument)); return xmlDocumentWithoutNs.ToString(); } private static XElement RemoveAllNamespaces(XElement xmlDocument) { if (!xmlDocument.HasElements) { XElement xElement = new XElement(xmlDocument.Name.LocalName); xElement.Value = xmlDocument.Value; foreach (XAttribute attribute in xmlDocument.Attributes()) xElement.Add(attribute); return xElement; } return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el))); }
private Regex M_RemoveDecl = new Regex(@"<\?xml.*?\?>");
This is to remove namespaces in documents. Makes the query of the document easier.
public static string RemoveAllNamespaces(string xmlDocument) { XElement xmlDocumentWithoutNs = RemoveAllNamespaces(XElement.Parse(xmlDocument)); return xmlDocumentWithoutNs.ToString(); } private static XElement RemoveAllNamespaces(XElement xmlDocument) { if (!xmlDocument.HasElements) { XElement xElement = new XElement(xmlDocument.Name.LocalName); xElement.Value = xmlDocument.Value; foreach (XAttribute attribute in xmlDocument.Attributes()) xElement.Add(attribute); return xElement; } return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el))); }
Wednesday, February 20, 2013
Updating ReportViewer to VS2010
OK, today I blew the dust off of a project that had ReportView 9.0. Since I had coded that website many moons have pasted and we have upgraded to VS2010.
I tried to just stay on RV9 however, one of the reports was erroring and I had javascript issues with the handler page that it inserts.
So, upgrade I did and not without google's help!
I had a report that was cause compile errors (The processing of Parent for the tablix ‘table1’ cannot be performed) with the grouping. I had to take out the "parent" tag and then all was well. Basically old versions glossed over this mishap, but not version 10. For the long explanation of why you need to do this, go here.
OrderNumGrp
">
<GroupExpressions>
<GroupExpression>=Fields!ClientOrderNum.Value</GroupExpression>
</GroupExpressions>
=Fields!ClosedDate.Value
Finally, when you are deploying to a server with IIS7. Make sure that you add the following to your web.config
webServer
>
...
ReportViewerWebControlHandler
" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
...
webServer>
Finally, as it always happends, when you get it onto the production server something else goes wrong. I was getting this error
Compiler Error Message: CS0433: The type 'Microsoft.Reporting.WebForms.ReportDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\8.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'c:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'
If you add the following to your web.config it tells .net to always direct to the new version
publicKeyToken="b03f5f7f11d50a3a" />
newVersion="10.0.0.0"/>
Happy Reporting
I tried to just stay on RV9 however, one of the reports was erroring and I had javascript issues with the handler page that it inserts.
So, upgrade I did and not without google's help!
- Install on your machine ReportViewer 10
- change the references in your project to point to version 10 of Microsoft.ReportViewer.Common and Microsoft.ReportViewer.WebForms
- If you registered your control, change this tag in your .aspx or control
- <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0...
I had a report that was cause compile errors (The processing of Parent for the tablix ‘table1’ cannot be performed) with the grouping. I had to take out the "parent" tag and then all was well. Basically old versions glossed over this mishap, but not version 10. For the long explanation of why you need to do this, go here.
">
<GroupExpressions>
<GroupExpression>=Fields!ClientOrderNum.Value</GroupExpression>
</GroupExpressions>
Finally, when you are deploying to a server with IIS7. Make sure that you add the following to your web.config
>
...
" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
...
webServer>
Finally, as it always happends, when you get it onto the production server something else goes wrong. I was getting this error
Compiler Error Message: CS0433: The type 'Microsoft.Reporting.WebForms.ReportDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\8.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'c:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'
If you add the following to your web.config it tells .net to always direct to the new version
Happy Reporting
Getting the results from a stored procedure into a single variable
I have used both the methods below to put result sets into a single variable. I will then use that variable as the message body to email the results to myself (or others).
Create Procedure DoSomethingEmailResult
....
I run a bunch of queried looking for data integrity issues, each result set I write into the following table.
declare @Problems table(
SiteId varchar(15) not null,
GenId int not null,
Alert varchar(max) not null,
ProblemDate datetime null default getdate(),
AlertLevel varchar(20) null
)
...
At the end, I want to email the results to myself because I am too lazy to go look for them.
This is how I get a multi-row table worth of results into a single variable. This becomes the body of my message.
select @result = coalesce(@result +
SiteId + char(9) +
cast(GenId as varchar) + char(9) +
alert + char(9) +
AlertLevel + '<br/><br/>','')
from @problems
Another query that I have used, but seems a bit more problematic
set @result = stuff(
(
select
SiteId + char(9) +
cast(GenId as varchar) + char(9) +
[Proc] + char(9) +
alert + char(9) +
cast(ProblemDate as varchar) + char(9) +
AlertLevel + '<br/><br/>'
from @ErrorTable
for xml Path(''), Type
).value('.', 'varchar(max)'), 0, 1, '');
Create Procedure DoSomethingEmailResult
....
I run a bunch of queried looking for data integrity issues, each result set I write into the following table.
declare @Problems table(
SiteId varchar(15) not null,
GenId int not null,
Alert varchar(max) not null,
ProblemDate datetime null default getdate(),
AlertLevel varchar(20) null
)
...
At the end, I want to email the results to myself because I am too lazy to go look for them.
This is how I get a multi-row table worth of results into a single variable. This becomes the body of my message.
select @result = coalesce(@result +
SiteId + char(9) +
cast(GenId as varchar) + char(9) +
alert + char(9) +
AlertLevel + '<br/><br/>','')
from @problems
Another query that I have used, but seems a bit more problematic
set @result = stuff(
(
select
SiteId + char(9) +
cast(GenId as varchar) + char(9) +
[Proc] + char(9) +
alert + char(9) +
cast(ProblemDate as varchar) + char(9) +
AlertLevel + '<br/><br/>'
from @ErrorTable
for xml Path(''), Type
).value('.', 'varchar(max)'), 0, 1, '');
Thursday, December 8, 2011
Problems that need documenting!
So, again, mostly for myself, but perhaps it will help others as well.
I ran into this bizzare problem with a GrdiView, drop down, and IE9 today. I don't think it has anything to do with a GridView btw. When I would select my drop down, go to choose a value, the drop down would loose focus and disappear. It doesn't happen with any other browser that I tested. To fix this problem I had to add a backgroup color to the drop down control. You got that right, backgroud:white;
The second problem that I ran into with the GridView was the scroll position wasn't being honored on IE9, and Mac Safari and IE. Googled for a while and finally found an uncommon feature. Asp.Net has browser senseing code in the framework. Well, when a new browser is released sometimes that code can become outdated. So to add fixes you use the app_browser folder and .browser file. Google ".browser file" and I am sure you will find a ton of information on this.
Tuesday, September 29, 2009
Playing with Silverlight
Most of the time I can't do anything that is too fancy or heavy on the client side. The clients who access the websites have really slow computers so we need to all the processing on the server that we can. Finally I have an application that might be for internal use so I decided to play with Silverlight to see what it could really do for us. This is a work in progress as I create my application...
Data AccessIn our existing environment most of our data access layer resides in web services. AND most of these web services return at least one DataSet. Problem #1 arose.
- Silverlight does not support web services that return DataSet. No problem at least for the moment I will code a shim to go between silverlight and the actual web service. I put a web service page into the web application that silverlight expects to be deployed from. Not real fond of this, but I will ponder to see if something better comes along
Creating the UI
Interesting model for the layout. At first it does not seem too bad. OK, dealt with Grids in the form of tables all my HTML career. Sometime down the line I realized that I had forgotten a field that needed to be inserted on the form. No problem, I will go back and put it in. Clumsy issue #1.
- When you go to insert a row, it is very easy to add the actual row to the grid definition. Just insert
where you want it to be. But when I need to assign what fields are in that row, each field assignment has a row designator in it. For instance, . This means that I have to reassign all my other previously inserted elements to their new row. Again, I will look to see if someone has a better way and report back. - In looking into issue #1 a little bit more, it appears (although not from any official blog) that we want to use a grid as the outer most element and then place the actual textboxes and such via stacked panels. This way we don't have to assign specific placing.
Images
Not thrilled that I can't get images to display. If you google how to do it the information seems to be very inconsistent. What types of images are supported, exactly how to reference an image in the "image" tag (relative URL, exact URL). It should not be this hard. I still can't get it to display. Interestingly I do see that it "reserves" space for it to display with some references, but it won't show in the application. Here is a really nice article for images. http://nerddawg.blogspot.com/2008/03/silverlight-2-demystifying-uri.html
Switching Pages
http://blogs.silverlight.net/blogs/jesseliberty/archive/2009/01/03/56420.aspx
Tuesday, August 11, 2009
Intro
This blog is solely for my musing. I may be venting or documenting something so I can refer back to it.
Subscribe to:
Posts (Atom)