<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Janne Mattila's blog : Microsoft Office SharePoint Server 2007</title><link>http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx</link><description>Tags: Microsoft Office SharePoint Server 2007</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Story of wrong content type and InfoPath publishing location</title><link>http://blogs.msdn.com/jannemattila/archive/2009/04/29/story-of-wrong-content-type-and-infopath-publishing-location.aspx</link><pubDate>Wed, 29 Apr 2009 13:54:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9575497</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/9575497.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=9575497</wfw:commentRss><description>&lt;p&gt;I found myself troubleshooting on issue that I thought shouldn’t be issue anymore. I have created InfoPath form and published it to the SharePoint. However when I created new form using that template it ended up using wrong content type at my library. And this happens even with the SP2 installed (both at the client and at the server) so I had to dig a little deeper.&lt;/p&gt;  &lt;p&gt;Here are the phases that I took:&lt;/p&gt;  &lt;p&gt;1. Created new InfoPath “Example form”.   &lt;br /&gt;2. Published it to the server called “&lt;em&gt;myserver&lt;/em&gt;” as an site content type.    &lt;br /&gt;3. Added new content type to “&lt;em&gt;mylist&lt;/em&gt;”.    &lt;br /&gt;4. Clicked “New example form” on the library and filled the form and saved it to the library.    &lt;br /&gt;5. Noticed that form is not the content type that I was expecting. It was default content type at the list... (which was Office document in my case since I had multiple content types at my list)&lt;/p&gt;  &lt;p&gt;Did some testing and noticed that it actually works fine &lt;strong&gt;IF&lt;/strong&gt; I use the “&lt;em&gt;myserver&lt;/em&gt;” in the address bar of IE and not the fully qualified domain name “&lt;em&gt;myserver.example.loc&lt;/em&gt;”. And now you’re thinking that I’ve just missed the Alternate Access Mappings (AAM) settings but &lt;strong&gt;&lt;u&gt;no&lt;/u&gt;&lt;/strong&gt;... I have those set for both addresses so that wasn’t the case.&lt;/p&gt;  &lt;p&gt;Next I tried to fiddle around with InfoPath and tried different publishing addresses at the “&lt;em&gt;Enter the location of your SharePoint or InfoPath Forms Services site:”&lt;/em&gt; –publishing wizard dialog:    &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="InfoPath publishing wizard dialog" border="0" alt="InfoPath publishing wizard dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Storyofwrongcontenttypeandpublishingloca_A6CD/image_3.png" width="584" height="441" /&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;And this is the place when it got interesting... Since I noticed that if I use “&lt;em&gt;myserver&lt;/em&gt;” address at the publishing wizard dialog then content type goes wrong when using SharePoint through “&lt;em&gt;myserver.example.loc&lt;/em&gt;” address. And also if I use the longer address at the publish wizard it doesn’t work at the SharePoint using the short address form.&lt;/p&gt;  &lt;p&gt;So next I thought that &lt;em&gt;Security Level&lt;/em&gt; could be the problem (which was set to &lt;em&gt;Domain&lt;/em&gt;):    &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="InfoPath publishing wizard dialog - Security level: Domain" border="0" alt="InfoPath publishing wizard dialog - Security level: Domain" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Storyofwrongcontenttypeandpublishingloca_A6CD/image_6.png" width="586" height="441" /&gt; &lt;/p&gt;  &lt;p&gt;...but if that would be the case then I couldn’t even use the form. Now the form works normally expect it will store the saved item into wrong content type. &lt;/p&gt;  &lt;p&gt;For me the case was closed. I just published the form in “long address format” and I was happy &lt;strong&gt;:-)&lt;/strong&gt; But I still wonder what went wrong in the background...    &lt;br /&gt;    &lt;br /&gt;Anyways... Happy hacking!    &lt;br /&gt;    &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9575497" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/InfoPath/default.aspx">InfoPath</category></item><item><title>SQL Server Profiler and SPQuery</title><link>http://blogs.msdn.com/jannemattila/archive/2008/06/21/sql-server-profiler-and-spquery.aspx</link><pubDate>Sat, 21 Jun 2008 22:58:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8633702</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/8633702.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=8633702</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; I’m using SPQuery to retrieve items from my SharePoint list and now I want to know little bit more about SPQuery properties. Actually I’m interested about performance related things since I’m not sure about my query currently. I currently have following code to retrieve my data:&lt;br&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPSite&lt;/font&gt; site = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;SPSite&lt;/font&gt;(&lt;font color="#a31515"&gt;"http://mysharepoint"&lt;/font&gt;))
{
  &lt;font color="#0000ff"&gt;using&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPWeb&lt;/font&gt; web = site.RootWeb)
  {
    &lt;font color="#2b91af"&gt;SPList&lt;/font&gt; docs = web.Lists[&lt;font color="#a31515"&gt;"MyDocs"&lt;/font&gt;];
    &lt;font color="#2b91af"&gt;SPQuery&lt;/font&gt; query = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;SPQuery&lt;/font&gt;();
    query.Query = &lt;font color="#a31515"&gt;@"&amp;lt;Query&amp;gt;
        &amp;lt;Where&amp;gt;
         &amp;lt;And&amp;gt;
           &amp;lt;Eq&amp;gt;
            &amp;lt;FieldRef Name='MyField' /&amp;gt;
            &amp;lt;Value Type='Text'&amp;gt;12345&amp;lt;/Value&amp;gt;
           &amp;lt;/Eq&amp;gt;
           &amp;lt;Eq&amp;gt;
            &amp;lt;FieldRef Name='ContentType' /&amp;gt;
            &amp;lt;Value Type='Text'&amp;gt;MyContentType&amp;lt;/Value&amp;gt;
           &amp;lt;/Eq&amp;gt;
         &amp;lt;/And&amp;gt;
        &amp;lt;/Where&amp;gt;
      &amp;lt;/Query&amp;gt;"&lt;/font&gt;;

    &lt;font color="#2b91af"&gt;SPListItemCollection&lt;/font&gt; items = docs.GetItems(query);
    &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPListItem&lt;/font&gt; item &lt;font color="#0000ff"&gt;in&lt;/font&gt; items)
    {
      &lt;font color="#2b91af"&gt;Console&lt;/font&gt;.WriteLine(&lt;font color="#a31515"&gt;"Item: "&lt;/font&gt; + item.Title);
    }
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Answer: &lt;/strong&gt;To answer this question I need to step into dark side for a minute... I mean that I’m going to ask you to play with SQL Server Profiler to analyze your query more closely. This is of course to give some ideas how to tune your query using query properties and nothing else. I don’t want you to start use any custom SQL queries or other weird hacks that you might come up. Just tune the query and that’s it. &lt;br&gt;&lt;strong&gt;NOTE: &lt;/strong&gt;&lt;u&gt;Do this stuff only in you own dev box&lt;/u&gt;. Don’t even think anything else. &lt;/p&gt;
&lt;p&gt;Before we start using the SQL Server Profiler you might want to stop SharePoint related services so that it’s easier to read the SQL trace. I’ve stopped &lt;em&gt;IIS Admin &lt;/em&gt;(+related), &lt;em&gt;Office SharePoint Server Search&lt;/em&gt; and &lt;em&gt;Windows SharePoint Services*&lt;/em&gt;. Now you can start SQL Server Profiler and you’re ready to start tracing. Just create new trace (File-&amp;gt;New Trace...) and select &lt;em&gt;Tuning&lt;/em&gt; for your template:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler1_2.png" target="_blank"&gt;&lt;img border="0" alt="SQLServerProfiler1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler1_thumb.png" width="640" height="404"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And if I now run your query I’ll get something like 200+ rows in my trace window. But you’re probably just interested for the rows that tell what is going on. If you pause the trace after the query then it’s most likely the last line in the grid:&lt;br&gt;&lt;img border="0" alt="SQLServerProfiler2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler2_068b6c0e-c3e1-4700-b280-ace6b48cf709.png" width="566" height="177"&gt;&amp;nbsp;&lt;br&gt;It gives you fairly long SQL (mine was ~4500 characters long) and it’s not trivial to understand what it is really doing. &lt;/p&gt;
&lt;p&gt;But first you probably notice the interesting&lt;em&gt;&amp;nbsp; SELECT TOP &lt;u&gt;2147483648&lt;/u&gt; ...&lt;/em&gt; And that’s the first thing you might want to change (of course you know best what you’re trying to achieve). But for that you have property called &lt;em&gt;RowLimit&lt;/em&gt;. So if you add “&lt;em&gt;query.RowLimit = 10;”&lt;/em&gt; to your code and re-run the trace you get following output:&lt;br&gt;&lt;img border="0" alt="SQLServerProfiler3" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler3_c772bad8-4893-4c39-be9e-3f0f40c253d9.png" width="468" height="93"&gt;&amp;nbsp;&lt;br&gt;So now you have &lt;em&gt;SELECT TOP 11 ...&lt;/em&gt; which is better (note that the actual limit is your &lt;em&gt;RowLimit + 1&lt;/em&gt;). If you only need to display &lt;em&gt;n&lt;/em&gt; rows from database then don’t retrieve all and display just &lt;em&gt;n =&amp;gt; &lt;/em&gt;Use &lt;em&gt;RowLimit &lt;/em&gt;to narrow down the resultset.&lt;/p&gt;
&lt;p&gt;Next thing we need to take into consideration is &lt;em&gt;ViewFields&lt;/em&gt;. If I know that I’m only going to show &lt;em&gt;Title&lt;/em&gt;, then why should I need to retrieve more fields. Let’s narrow down the fields using &lt;em&gt;ViewFields&lt;/em&gt;:&lt;br&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;query.ViewFields = &lt;font color="#a31515"&gt;@"&amp;lt;FieldRef Name='ID'/&amp;gt;
                     &amp;lt;FieldRef Name='Title'/&amp;gt;"&lt;/font&gt;;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;
&lt;p&gt;And again let’s test the trace and compare the query for the first trace. You may notice that the SQL is &lt;em&gt;only&lt;/em&gt; ~3000 chars long anymore and amount of columns at the resultset is a lot less (screenshot from management studio when both queries have been executed):&lt;br&gt;&lt;img border="0" alt="SQLServerProfiler4" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler4_74dcdd16-91ed-4f65-9b7d-7fb9e23e54d9.png" width="384" height="207"&gt;&amp;nbsp;&lt;br&gt;Notice the size of scrollbar…. larger is better &lt;strong&gt;:-)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now I have just added few lines of code and the result is ~1500 shorter SQL and we’re only getting the amount of rows from DB that we need to. I’m not going to play with another properties but if you’re interested you might want to start with &lt;em&gt;Include*&lt;/em&gt; properties. &lt;/p&gt;
&lt;p&gt;I showed small example that how can use SQL Server toolset to verify (at least for some extend) that your queries are going for the right direction. &lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8633702" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category></item><item><title>Link: SharePoint slow spin-up times…</title><link>http://blogs.msdn.com/jannemattila/archive/2008/05/29/link-sharepoint-slow-spin-up-times.aspx</link><pubDate>Thu, 29 May 2008 18:14:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8558858</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/8558858.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=8558858</wfw:commentRss><description>&lt;p&gt;I accidently found myself on this page: &lt;a href="http://jritmeijer.spaces.live.com/blog/cns!8A48A27460FB898A!965.entry" target="_blank"&gt;SharePoint 2007 Quirks - Solving painfully slow spin-up times&lt;/a&gt;. After reading that article I was forced to test that. And my &lt;em&gt;stsadm&lt;/em&gt; experience was really fast after that! So this link deserves a link post even if I don’t do those normally &lt;strong&gt;:-) &lt;/strong&gt;&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8558858" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category></item><item><title>CRM 4.0 (or SharePoint or custom application) and DebugView</title><link>http://blogs.msdn.com/jannemattila/archive/2008/05/07/crm-4-0-or-sharepoint-or-custom-application-and-debugview.aspx</link><pubDate>Wed, 07 May 2008 10:04:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8465208</guid><dc:creator>jannemattila</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/8465208.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=8465208</wfw:commentRss><description>&lt;p&gt;Every now and then I’m find myself trying to solve same issues over and over again :-) That’s why I found myself (again) using &lt;em&gt;DebugView&lt;/em&gt; as my debugging assistant at remote box. If you don’t know what &lt;em&gt;DebugView&lt;/em&gt; is then you should definitely try it out. I’m going to give you few ideas how you could use it at your applications. You can download the &lt;em&gt;DebugView&lt;/em&gt; from &lt;a title="DebugView download" href="http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx" target="_blank"&gt;Technet&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Why do I use &lt;em&gt;DebugView&lt;/em&gt;? Well I want to get debug messages from running system BUT... I don’t want to write to EventLog or to File since it’s totally unnecessary to write all the messages all the time. I just want messages when I’m ready to observe the system. And DebugView is handy tool for that. Here is list of steps how I normally implement that kind of approach:&lt;br&gt;1) Create log class that implements logging/tracing/debugging (this is pretty much just wrapper to few simple method calls) (I recommend making this as singleton)&lt;br&gt;2) Use you log class in your application/solution&lt;br&gt;3) Use &lt;em&gt;DebugView &lt;/em&gt;to follow the trace messages written by your log class&lt;/p&gt; &lt;p&gt;In 1) I mention that I recommend using singleton approach at the log class. This is important especially at the CRM 4.0 where you need to add default trace listener so that you’ll get the trace messages. Here is the code example for that:&lt;/p&gt; &lt;p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Diagnostics;
&lt;font color="#008000"&gt;// ...
&lt;/font&gt;&lt;font color="#2b91af"&gt;Trace&lt;/font&gt;.Listeners.Add(&lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;DefaultTraceListener&lt;/font&gt;());&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;
&lt;p&gt;After you have added the default listener you can just use this oneliner:&lt;/p&gt;
&lt;p&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#2b91af"&gt;Trace&lt;/font&gt;.WriteLine(&lt;font color="#a31515"&gt;"My Trace: "&lt;/font&gt; + message);&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;
&lt;p&gt;Now your trace can be seen at the &lt;em&gt;DebugView&lt;/em&gt;:&lt;br&gt;&lt;img border="0" alt="DebugView" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CRM4.0andDebugView_60C3/DebugView_c8bc2cb2-c36a-463a-9b14-168b4e41f642.png" width="470" height="243"&gt;&lt;br&gt;(here is CRM 4.0 where I have menu item that points to custom ASPX page and I’m using “My Trace” to see what’s happening in there)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;DebugView&lt;/em&gt; has many built-in functionalities like “Save As” etc. that can help you on your debug/trace efforts. So I recommend that you learn to play around with it.&lt;/p&gt;
&lt;p&gt;I also had the magic word “SharePoint” in my title. That is for the simple reason that this same story applies to SharePoint too. And don’t forget... Since &lt;em&gt;System.Diagnostics.Trace&lt;/em&gt; is implemented at the .NET Framework this story also applies to all other applications which are built on top of that.&lt;/p&gt;
&lt;p&gt;You might also want to read my previous post about tracing: &lt;a title="CRM 4.0, SharePoint and ASP.NET Trace" href="http://blogs.msdn.com/jannemattila/archive/2008/02/23/crm-4-0-sharepoint-and-asp-net-trace.aspx" target="_blank"&gt;CRM 4.0, SharePoint and ASP.NET Trace&lt;/a&gt;.&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8465208" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Application+Development/default.aspx">Application Development</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+CRM/default.aspx">Microsoft CRM</category></item><item><title>Custom SharePoint application and System.IO.FileNotFoundException</title><link>http://blogs.msdn.com/jannemattila/archive/2008/02/23/custom-sharepoint-application-and-system-io-filenotfoundexception.aspx</link><pubDate>Sat, 23 Feb 2008 23:55:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7862558</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/7862558.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=7862558</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; I have normal user access rights at SharePoint but I'm administrator of the physical SharePoint box. I don't have access rights to SharePoint databases but I still need to run few lines of code against SharePoint. I have created small console application but when I run it I get nasty &lt;em&gt;System.IO.FileNotFoundException:&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;img height="333" alt="FileNotFoundException" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/RunSharePointAdmintaskwithlocalserveruse_102D7/MySharePointTask1_056daa7f-fecc-473d-b6b9-ed1cfac67e30.png" width="668" border="0"&gt; &lt;/p&gt; &lt;p&gt;What can I do?&lt;/p&gt; &lt;p&gt;&lt;strong&gt;My answer: &lt;/strong&gt;So you have used &lt;em&gt;Microsoft.SharePoint.dll&lt;/em&gt; and probably you have something like this in your code: "&lt;em&gt;using (SPSite site = new SPSite("..."))&lt;/em&gt;" and that causes the exception. Well that exception is actually pretty understandable since you're using API that connects directly to the SharePoint databases... and you mentioned that you don't have access rights to databases so it makes sense. And on top of that you have only standard user rights to SharePoint so we're at the dead end anyway. &lt;/p&gt; &lt;p&gt;That means that we need to change our approach a little bit. Of course the solution differs little bit what you're trying to do but I think that you have few options. First one is that you could use SharePoint web services to implement your functionality. I know that it's not the easiest way to go but it should to the trick. Another approach could be custom application page that does the trick. It is a bit "hacky" approach but if you need to "&lt;em&gt;do something against SharePoint&lt;/em&gt;" that is something you could try. I'll give you example so that you'll get the idea what I mean.&lt;/p&gt; &lt;p&gt;First create your custom aspx page into layouts folder (&lt;em&gt;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\&lt;/em&gt;). I created &lt;em&gt;MySharePointAdminTask.aspx&lt;/em&gt; to the root of layouts but you should add subfolder with correct naming (e.g. &lt;em&gt;Company.Project.Functionality&lt;/em&gt;). I added following code to my page:&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&amp;lt;%&lt;font color="#0000ff"&gt;@&lt;/font&gt; &lt;font color="#a31515"&gt;Page&lt;/font&gt; &lt;font color="#ff0000"&gt;language&lt;/font&gt;&lt;font color="#0000ff"&gt;="C#"&lt;/font&gt; %&amp;gt;
&amp;lt;%&lt;font color="#0000ff"&gt;@&lt;/font&gt; &lt;font color="#a31515"&gt;Import&lt;/font&gt; &lt;font color="#ff0000"&gt;Namespace&lt;/font&gt;&lt;font color="#0000ff"&gt;="Microsoft.SharePoint"&lt;/font&gt; %&amp;gt;
&amp;lt;%&lt;font color="#0000ff"&gt;@&lt;/font&gt; &lt;font color="#a31515"&gt;Import&lt;/font&gt; &lt;font color="#ff0000"&gt;Namespace&lt;/font&gt;&lt;font color="#0000ff"&gt;="Microsoft.SharePoint.WebControls"&lt;/font&gt; %&amp;gt;

&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;script&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="server"&amp;gt;
&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; Page_load(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, &lt;font color="#2b91af"&gt;EventArgs&lt;/font&gt; e)
 {
  &lt;font color="#0000ff"&gt;if&lt;/font&gt; (Request.IsLocal == &lt;font color="#0000ff"&gt;true&lt;/font&gt; &amp;amp;&amp;amp; Request.IsSecureConnection == &lt;font color="#0000ff"&gt;true&lt;/font&gt;)
  {
    &lt;font color="#2b91af"&gt;SPSecurity&lt;/font&gt;.RunWithElevatedPrivileges(&lt;font color="#0000ff"&gt;delegate&lt;/font&gt;()
    {
      &lt;font color="#0000ff"&gt;using&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPSite&lt;/font&gt; site = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;SPSite&lt;/font&gt;(&lt;font color="#2b91af"&gt;SPControl&lt;/font&gt;.GetContextSite(&lt;font color="#2b91af"&gt;HttpContext&lt;/font&gt;.Current).ID))
      {
        &lt;font color="#0000ff"&gt;using&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPWeb&lt;/font&gt; web = site.RootWeb)
        {
          &lt;font color="#008000"&gt;// TODO: add your code here
&lt;/font&gt;          &lt;font color="#008000"&gt;// Example:
&lt;/font&gt;          Response.Write(web.Title + &lt;font color="#a31515"&gt;" at url "&lt;/font&gt; + web.Url);
        }
      }
    });
  }
  &lt;font color="#0000ff"&gt;else
&lt;/font&gt;  {
    Response.StatusCode = 404;
    Response.SuppressContent = &lt;font color="#0000ff"&gt;true&lt;/font&gt;;
    Response.End();
  }
 }
&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;script&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;

&amp;lt;!&lt;/font&gt;&lt;font color="#a31515"&gt;DOCTYPE&lt;/font&gt; &lt;font color="#ff0000"&gt;html&lt;/font&gt; &lt;font color="#ff0000"&gt;PUBLIC&lt;/font&gt; &lt;font color="#0000ff"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/font&gt; 
 &lt;font color="#0000ff"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&lt;/font&gt; 
&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;html&lt;/font&gt; &lt;font color="#ff0000"&gt;xmlns&lt;/font&gt;&lt;font color="#0000ff"&gt;="http://www.w3.org/1999/xhtml"&lt;/font&gt; &lt;font color="#0000ff"&gt;&amp;gt;
&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;head&lt;/font&gt; &lt;font color="#ff0000"&gt;id&lt;/font&gt;&lt;font color="#0000ff"&gt;="Head1"&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="server"&amp;gt;
&lt;/font&gt;  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;title&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;MySharePointAdminTask&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;title&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;head&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;body&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&lt;/font&gt;  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;form&lt;/font&gt; &lt;font color="#ff0000"&gt;id&lt;/font&gt;&lt;font color="#0000ff"&gt;="form1"&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;="server"&amp;gt;
&lt;/font&gt;  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&lt;/font&gt;    &lt;font color="#008000"&gt;&amp;lt;!-- TODO: add your code here --&amp;gt;
&lt;/font&gt;  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&lt;/font&gt;  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;form&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;body&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;html&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;I have some basic checks at line 8 to see that is this request local and is the connection secure but in order to make this even a bit safe &lt;u&gt;you need to add more checks &lt;/u&gt;to it. &lt;u&gt;If that line fails then everybody who knows the url can execute code with elevated privileges&lt;/u&gt;. So you need to be really careful if you want to use this kind of approach and using code behind class would be much better than this inline example. On lines 12 to 20 I'll just do my fancy SharePoint stuff (in this example I'll just write out title and url of the site).&lt;/p&gt;
&lt;p&gt;On lines 25 to 27 I'll just make the page look like 404 page just in case some of our checks didn't pass. We only want to run this code by the local user. So let see what is the end result:&lt;/p&gt;
&lt;p&gt;For the local user it looks like this (and the user has only normal SharePoint access rights):&lt;/p&gt;
&lt;p&gt;&lt;img height="180" alt="SharePoint Admin task for the local user" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/RunSharePointAdmintaskwithlocalserveruse_102D7/SPAdmin1_02c5169f-2972-45de-bae3-639c5dadbbac.png" width="564" border="0"&gt; &lt;/p&gt;
&lt;p&gt;For the remote user (even with System admin rights):&lt;/p&gt;
&lt;p&gt;&lt;img height="261" alt="SharePoint Admin task for the remote user" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/RunSharePointAdmintaskwithlocalserveruse_102D7/SPAdmin2_bc1d8eb7-c23d-4fb6-ab40-0986621df905.png" width="549" border="0"&gt; &lt;/p&gt;
&lt;p&gt;So this kind of approach is okay for small SharePoint operations but if you need to do more complex and long running operations then you need to reconsider your options. It's a bit hacky approach but it works :-)&lt;br&gt;&lt;br&gt;Anyway... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7862558" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category></item><item><title>CRM 4.0, SharePoint and ASP.NET Trace</title><link>http://blogs.msdn.com/jannemattila/archive/2008/02/23/crm-4-0-sharepoint-and-asp-net-trace.aspx</link><pubDate>Sat, 23 Feb 2008 21:12:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7860388</guid><dc:creator>jannemattila</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/7860388.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=7860388</wfw:commentRss><description>&lt;p&gt;Sometimes I tend to forget how much stuff is built into .NET Framework. Framework gives you nice set of features that you can use without writing a single line of code. ASP.NET Trace is one of them. I know that it's nothing new but I think that it's still used mainly in custom ASP.NET applications. But if you work with products like CRM or SharePoint... you kind of forget that those applications are built on top of ASP.NET and you can still benefit from the features that are part of the framework. So let's refresh our memory so that we can use this feature to build better solutions. &lt;/p&gt; &lt;p&gt;See also good post regarding tracing SharePoint in here "&lt;a title="Enabling Page Level Tracing For SharePoint ASPX Forms" href="http://blogs.threewill.com/implementingsharepoint/Lists/Categories/Category.aspx?Name=User%20Interface" target="_blank"&gt;Enabling Page Level Tracing For SharePoint ASPX Forms&lt;/a&gt;".&lt;/p&gt; &lt;p&gt;Okay let's first enable trace at the web.config (same changes apply for CRM and SharePoint):&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;?&lt;/font&gt;&lt;font color="#a31515"&gt;xml&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;version&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;1.0&lt;/font&gt;"&lt;font color="#0000ff"&gt;?&amp;gt;
&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;configuration&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
 &amp;lt;!--&lt;/font&gt;&lt;font color="#008000"&gt; ... &lt;/font&gt;&lt;font color="#0000ff"&gt;--&amp;gt;
 &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;system.web&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
  &amp;lt;!--&lt;/font&gt;&lt;font color="#008000"&gt; ... &lt;/font&gt;&lt;font color="#0000ff"&gt;--&amp;gt;
  &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;trace&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;requestLimit&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;100&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;enabled&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;true&lt;/font&gt;"&lt;font color="#0000ff"&gt;/&amp;gt;
  &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;compilation&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;debug&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;true&lt;/font&gt;"&lt;font color="#0000ff"&gt; /&amp;gt;
  &amp;lt;!--&lt;/font&gt;&lt;font color="#008000"&gt; ... &lt;/font&gt;&lt;font color="#0000ff"&gt;--&amp;gt;
 &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;system.web&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
 &amp;lt;!--&lt;/font&gt;&lt;font color="#008000"&gt; ... &lt;/font&gt;&lt;font color="#0000ff"&gt;--&amp;gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;configuration&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;So in order to enable the trace you just have to make sure that you have trace (line 6) and debug enabled (line 7). After that you're good to go and trace your application.&lt;/p&gt;
&lt;p&gt;I just retrieved front page from my SharePoint (&lt;em&gt;http://demo1&lt;/em&gt;) and then clicked url to custom application page. Then I typed in the trace url &lt;em&gt;http://demo1/Trace.axd&lt;/em&gt; and checkout the results:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/SPSTrace1_2.png" target="_blank"&gt;&lt;img height="442" alt="SharePoint trace" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/SPSTrace1_thumb.png" width="640" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And in more detailed (I just clicked the &lt;em&gt;Pages/Default.aspx&lt;/em&gt;):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/SPSTrace2_2.png" target="_blank"&gt;&lt;img height="671" alt="SharePoint trace detailed" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/SPSTrace2_thumb.png" width="650" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And same thing works with CRM 4.0 too... but remember that it's &lt;strong&gt;unsupported&lt;em&gt; &lt;/em&gt;to modify web.config in CRM&lt;/strong&gt; so create back up copy so that you can restore the original file when you need to clean up your modifications.&lt;/p&gt;
&lt;p&gt;In my CRM I opened url &lt;em&gt;http://crmserver/Contoso&lt;/em&gt; to goto tenant named &lt;em&gt;Contoso.&lt;/em&gt; After that I used my custom aspx page from &lt;em&gt;ISV&lt;/em&gt;-folder. And then I checked the trace:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/CRMTrace1_2.png" target="_blank"&gt;&lt;img height="301" alt="CRM Trace" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/CRMTrace1_thumb.png" width="640" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And if you look at more detailed view of the trace:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/CRMTrace2_2.png" target="_blank"&gt;&lt;img height="430" alt="CRM Trace details" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TracingCRM4.0orSharePoint_A9F6/CRMTrace2_thumb.png" width="640" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And you can easily see the amount of stuff that is put into the application state and especially for &lt;em&gt;CRMWindowInfo_CacheKey&lt;/em&gt;. Using this technique you can find e.g performance issues in your code quite easily.&lt;/p&gt;
&lt;p&gt;I actually used this method to debug some AJAX and web services issues and it worked really well because I could check out from the trace what has happened and when. &lt;/p&gt;
&lt;p&gt;To summarize.... you should refresh your memory about things that you get straight from the platform. It can save lot of your time. At least it happened to me :-)&lt;br&gt;&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7860388" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+CRM/default.aspx">Microsoft CRM</category></item><item><title>Catching unhandled exceptions in SharePoint</title><link>http://blogs.msdn.com/jannemattila/archive/2008/02/04/catching-unhandled-exceptions-in-sharepoint.aspx</link><pubDate>Mon, 04 Feb 2008 19:13:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7440474</guid><dc:creator>jannemattila</dc:creator><slash:comments>18</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/7440474.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=7440474</wfw:commentRss><description>&lt;p&gt;If you have done some dev stuff with MOSS you have most likely seen this:&lt;/p&gt; &lt;p&gt;&lt;img height="191" alt="UnexpectedError" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/UnhandledexceptionsinSharePoint_E4E3/UnexpectedError_f71ed40f-d19b-4a3b-b328-58e6dd79b9d7.png" width="402" border="0"&gt; &lt;/p&gt; &lt;p&gt;"&lt;em&gt;An unexpected error has occurred. &lt;/em&gt;" is something that you probably don't want to see at your browser.... you want to have customized error page. In ASP.NET application you normally put &lt;em&gt;Application_Error&lt;/em&gt; into you &lt;em&gt;global.asax &lt;/em&gt;file. However in SharePoint that place has been taken by the product itself :-) So if you want to do customized approach then you can take &lt;em&gt;HttpModule&lt;/em&gt; approach which I'm going to go through in this post. &lt;/p&gt; &lt;p&gt;So let's create our custom exception handler http module. Here's the code for that:&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web;

&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;MyExceptionHandler&lt;/font&gt; : &lt;font color="#2b91af"&gt;IHttpModule
&lt;/font&gt;{
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; Dispose()
  {
  }

  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; Init(&lt;font color="#2b91af"&gt;HttpApplication&lt;/font&gt; context)
  {
    context.Error += &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;EventHandler&lt;/font&gt;(context_Error);
  }

  &lt;font color="#0000ff"&gt;void&lt;/font&gt; context_Error(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, &lt;font color="#2b91af"&gt;EventArgs&lt;/font&gt; e)
  {
    &lt;font color="#2b91af"&gt;Exception&lt;/font&gt;[] unhandledExceptions = &lt;font color="#2b91af"&gt;HttpContext&lt;/font&gt;.Current.AllErrors;

    &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#2b91af"&gt;Exception&lt;/font&gt; ex &lt;font color="#0000ff"&gt;in&lt;/font&gt; unhandledExceptions)
    {
      &lt;font color="#008000"&gt;// TODO: log your errors
&lt;/font&gt;    }

    &lt;font color="#2b91af"&gt;HttpContext&lt;/font&gt;.Current.Server.ClearError();
    &lt;font color="#2b91af"&gt;HttpContext&lt;/font&gt;.Current.Response.Clear();
    &lt;font color="#2b91af"&gt;HttpContext&lt;/font&gt;.Current.Server.Transfer(&lt;font color="#a31515"&gt;"/_layouts/MyCustomErrorPage.aspx"&lt;/font&gt;);
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;You can probably see from the code that I'll attach my code to the &lt;em&gt;Error&lt;/em&gt; event and in my event I'll do some basic stuff and then transfer to my &lt;em&gt;MyCustomErrorPage.aspx.&lt;/em&gt; I used &lt;em&gt;Server.Transfer &lt;/em&gt;just because I want user to stay at the same url where exception happened. If I would use &lt;em&gt;Response.Redirect&lt;/em&gt; it would "change" the url at the users browser. Same "change" would happen if your custom error page would be normal SharePoint publishing page (i.e. &lt;em&gt;/Pages/MyCustomErrorPage.aspx&lt;/em&gt;). If the url stays the same the user can actually press F5 and retry the operation right away. Of course it can be bad thing too and you may want to redirect to another page to avoid creating the same exception all over again. I'll let you decide what you want :-) So do some testing and then decide what's good for you. &lt;/p&gt;
&lt;p&gt;But one important thing to notice. You need to put your &lt;em&gt;IHttpModule&lt;/em&gt; before SharePoint specific modules in your &lt;em&gt;web.config&lt;/em&gt; or otherwise your error routines may not work as you would expect. Here's example from that:&lt;/p&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;?&lt;/font&gt;&lt;font color="#a31515"&gt;xml&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;version&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;1.0&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;encoding&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;UTF-8&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;standalone&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;yes&lt;/font&gt;"&lt;font color="#0000ff"&gt;?&amp;gt;
&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;configuration&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
 &amp;lt;!--&lt;/font&gt;&lt;font color="#008000"&gt; ... &lt;/font&gt;&lt;font color="#0000ff"&gt;--&amp;gt;
  &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;httpModules&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
   &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;clear&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
   &lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;strong&gt;&lt;font color="#a31515"&gt;add&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;MyExceptionHandler&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;/strong&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;MyExceptionHandler,Example, 
      Version=1.0.0.0, Culture=neutral,PublicKeyToken=34a2bd01f6f6eb10&lt;/font&gt;"&lt;/strong&gt;&lt;font color="#0000ff"&gt;&lt;strong&gt; /&amp;gt;&lt;/strong&gt;
   &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;add&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;SPRequest&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, 
      Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&lt;/font&gt;"&lt;font color="#0000ff"&gt; /&amp;gt;
   &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;add&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;OutputCache&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;System.Web.Caching.OutputCacheModule&lt;/font&gt;"&lt;font color="#0000ff"&gt; /&amp;gt;
   &amp;lt;!--&lt;/font&gt;&lt;font color="#008000"&gt; ... &lt;/font&gt;&lt;font color="#0000ff"&gt;--&amp;gt;

  &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;configuration&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;See line 6 where I put my exception handler definition. &lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7440474" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category></item><item><title>Create Silverlight 1.1 applications for SharePoint with VS2008</title><link>http://blogs.msdn.com/jannemattila/archive/2007/12/19/create-silverlight-1-1-applications-for-sharepoint-with-vs2008.aspx</link><pubDate>Thu, 20 Dec 2007 00:26:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6809950</guid><dc:creator>jannemattila</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/6809950.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=6809950</wfw:commentRss><description>&lt;p&gt;Title says it all :-) My plan is to create small walkthrough how you can create your own Silverlight 1.1 application with Visual Studio 2008 and then run it in SharePoint. And I don't want to install a lot of stuff to my SharePoint environment so I'll just create simple web part to host the Silverlight application. All development work will be done outside SharePoint environment.&lt;/p&gt; &lt;p&gt;If you're new to Silverlight then I suggest you start by looking at least &lt;a href="http://silverlight.net/" target="_blank"&gt;silverlight.net&lt;/a&gt; and cool &lt;a href="http://blogs.msdn.com/coding4fun/archive/2007/09/19/5002772.aspx" target="_blank"&gt;Coding4Fun Silverlight 8-Ball example&lt;/a&gt;. The first link is starting point for Silverlight development and the second one is really cool sample that shows how can you create 8-Ball game with Silverlight. &lt;/p&gt; &lt;p&gt;Now you know something about Silverlight :-) So we can get started with my example. &lt;/p&gt; &lt;p&gt;I have VS2008 running on my Vista and I have downloaded and installed &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=25144C27-6514-4AD4-8BCB-E2E051416E03&amp;amp;displaylang=en" target="_blank"&gt;Microsoft Silverlight 1.1 Tools Alpha for Visual Studio 2008&lt;/a&gt; to help me developing Silverlight applications. It has new project template that has all the necessary stuff already set up to build Silverlight 1.1 application. I also have SharePoint running in my Virtual PC and it's configured so that I can connect to it directly from my host machine (i.e. http://demo1:1000 in my host IE connects to the virtualized SharePoint).&lt;/p&gt; &lt;p&gt;At first I'll modify SharePoint so that I can host my new applications in there. Let's add few folders under &lt;em&gt;_LAYOUTS&lt;/em&gt;:&lt;/p&gt; &lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="247" alt="IIS1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/IIS1_3.png" width="157" border="0"&gt; &lt;/p&gt; &lt;p&gt;&lt;em&gt;ClientBin&lt;/em&gt; is folder that will contain all Silverlight client .&lt;em&gt;dll&lt;/em&gt; files (=if you build your Silverlight project you automatically get &lt;em&gt;ClientBin&lt;/em&gt; under your project folder which contains your projects client assemblies). &lt;/p&gt; &lt;p&gt;&lt;em&gt;Silverlight&lt;/em&gt; folder is used to store .&lt;em&gt;xaml&lt;/em&gt; files (=Silverlight pages). I also need to change settings for both of them in order make things work. First I'll change &lt;em&gt;ClientBin&lt;/em&gt; settings:&lt;/p&gt; &lt;p&gt;Set only &lt;em&gt;Read&lt;/em&gt; access and also set &lt;em&gt;Execute permissions&lt;/em&gt; to &lt;em&gt;None&lt;/em&gt;:&lt;/p&gt; &lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="336" alt="IIS2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/IIS2_6.png" width="356" border="0"&gt; &lt;/p&gt; &lt;p&gt;Then I'll add &lt;em&gt;.dll&lt;/em&gt; to allowed mime types (and &lt;em&gt;.pdb&lt;/em&gt; for future debugging purposes :-):&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/IIS3_2.png" target="_blank"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="474" alt="IIS3" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/IIS3_thumb.png" width="563" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Then I'll change the &lt;em&gt;Silverlight&lt;/em&gt; folders settings to support &lt;em&gt;.xaml&lt;/em&gt; extension:&lt;/p&gt; &lt;p&gt;&lt;img height="117" alt="IIS4" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/IIS4_041be262-c995-4972-984e-a12164162ccc.png" width="350" border="0"&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now SharePoint is set up... but let's create web part that will actually host the Silverlight application in our page. Here's the code for that:&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Runtime.InteropServices;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web.UI;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web.UI.WebControls.WebParts;

&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; Silverlight_Web_Part
{
  [&lt;font color="#2b91af"&gt;Guid&lt;/font&gt;(&lt;font color="#a31515"&gt;"fc852641-9955-433c-945e-d773f46351eb"&lt;/font&gt;)]
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;Silverlight_Web_Part&lt;/font&gt; : &lt;font color="#008080"&gt;WebPart&lt;/font&gt;
  {
    &lt;font color="#0000ff"&gt;string&lt;/font&gt; xamlFile;
    [&lt;font color="#008080"&gt;WebBrowsable&lt;/font&gt;(&lt;font color="#0000ff"&gt;true&lt;/font&gt;), &lt;font color="#008080"&gt;Personalizable&lt;/font&gt;(&lt;font color="#0000ff"&gt;true&lt;/font&gt;)]
    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;string&lt;/font&gt; XamlFile
    {
      &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; xamlFile; }
      &lt;font color="#0000ff"&gt;set&lt;/font&gt; { xamlFile = &lt;font color="#0000ff"&gt;value&lt;/font&gt;; }
    }

    &lt;font color="#0000ff"&gt;public&lt;/font&gt; Silverlight_Web_Part()
    {
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.ExportMode = &lt;font color="#008080"&gt;WebPartExportMode&lt;/font&gt;.All;
    }

    &lt;font color="#0000ff"&gt;protected&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; Render(&lt;font color="#008080"&gt;HtmlTextWriter&lt;/font&gt; writer)
    {
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (&lt;font color="#0000ff"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="#0000ff"&gt;this&lt;/font&gt;.XamlFile) == &lt;font color="#0000ff"&gt;false&lt;/font&gt;)
      {
        writer.Write(&lt;font color="#a31515"&gt;"&amp;lt;div id='SilverlightControlHost' "&lt;/font&gt; + 
          &lt;font color="#a31515"&gt;"style='width: 640px; height: 480px;'&amp;gt;&amp;lt;/div&amp;gt;"&lt;/font&gt;);
        writer.Write(&lt;font color="#a31515"&gt;"&amp;lt;script type='text/javascript' "&lt;/font&gt; +
            &lt;font color="#a31515"&gt;"language='JavaScript' src='/_layouts/Silverlight.js'&amp;gt;&amp;lt;/script&amp;gt;"&lt;/font&gt;);
        writer.Write(&lt;font color="#a31515"&gt;"&amp;lt;script type='text/javascript' "&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"language='JavaScript' src='/_layouts/SilverlightStarter.js'&amp;gt;&amp;lt;/script&amp;gt;"&lt;/font&gt;);
        writer.Write(&lt;font color="#a31515"&gt;"&amp;lt;script type='text/javascript' "&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"language='JavaScript'&amp;gt;createSilverlight('"&lt;/font&gt; + xamlFile + &lt;font color="#a31515"&gt;"');&amp;lt;/script&amp;gt;"&lt;/font&gt;);
      }
      &lt;font color="#0000ff"&gt;else
&lt;/font&gt;      {
        writer.Write(&lt;font color="#a31515"&gt;"Xaml file is not selected."&lt;/font&gt;);
      }
    }
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;My web part uses &lt;em&gt;Silverlight.js&lt;/em&gt; and &lt;em&gt;SilverlightStarter.js&lt;/em&gt; files. &lt;em&gt;SilverLight.js&lt;/em&gt; is the same file that is included at the project when you create Silverlight 1.1 project in VS. &lt;em&gt;SilverlightStarter.js&lt;/em&gt; is almost copy paste from that project template too but I have just modified it a little bit to support sending XAML file as parameter:&lt;/p&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;function&lt;/font&gt; createSilverlight(filename)
{
  Silverlight.createObjectEx({
    source: filename,
    parentElement: document.getElementById(&lt;font color="#a31515"&gt;"SilverlightControlHost"&lt;/font&gt;),
    id: &lt;font color="#a31515"&gt;"SilverlightControl"&lt;/font&gt;,
    properties: {
      width: &lt;font color="#a31515"&gt;"100%"&lt;/font&gt;,
      height: &lt;font color="#a31515"&gt;"100%"&lt;/font&gt;,
      version: &lt;font color="#a31515"&gt;"1.1"&lt;/font&gt;,
      enableHtmlAccess: &lt;font color="#a31515"&gt;"true"
&lt;/font&gt;    },
    events: {}
  });
   
  document.body.onload = &lt;font color="#0000ff"&gt;function&lt;/font&gt;() {
   &lt;font color="#0000ff"&gt;var&lt;/font&gt; silverlightControl = document.getElementById(&lt;font color="#a31515"&gt;'SilverlightControl'&lt;/font&gt;);
   &lt;font color="#0000ff"&gt;if&lt;/font&gt; (silverlightControl)
   silverlightControl.focus();
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;And if you checkout my web part code on line 35 you actually notice that I'll just pass on the XAML file that has been set in web part properties:&lt;/p&gt;
&lt;p&gt;&lt;img height="117" alt="WebPart" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/WebPart_46bb276c-02b5-434d-8ccc-024e7b7515ab.png" width="239" border="0"&gt; &lt;/p&gt;
&lt;p&gt;Now we just need to add some Silverlight stuff and we're done. So here is the content of the &lt;em&gt;Page.xaml &lt;/em&gt;(=THE application :-):&lt;/p&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Canvas&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;x:Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;parentCanvas&lt;/font&gt;"
&lt;font color="#0000ff"&gt;    &lt;/font&gt;&lt;font color="#ff0000"&gt;xmlns&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;http://schemas.microsoft.com/client/2007&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
    &lt;/font&gt;&lt;font color="#ff0000"&gt;xmlns:x&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
    &lt;/font&gt;&lt;font color="#ff0000"&gt;Loaded&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;Page_Loaded&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
    &lt;/font&gt;&lt;font color="#ff0000"&gt;x:Class&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;MySilverLight.Page;assembly=/_LAYOUTS/ClientBin/MySilverLight.dll&lt;/font&gt;"
&lt;font color="#0000ff"&gt;    &lt;/font&gt;&lt;font color="#ff0000"&gt;Width&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;640&lt;/font&gt;"
&lt;font color="#0000ff"&gt;    &lt;/font&gt;&lt;font color="#ff0000"&gt;Height&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;480&lt;/font&gt;"
&lt;font color="#0000ff"&gt;    &lt;/font&gt;&lt;font color="#ff0000"&gt;Background&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;White&lt;/font&gt;"&lt;font color="#0000ff"&gt;    
    &amp;gt;

 &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Rectangle&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;x:Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;MyRectangle&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
       &lt;/font&gt;&lt;font color="#ff0000"&gt;Canvas.Top&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;25&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;Canvas.Left&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;25&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
       &lt;/font&gt;&lt;font color="#ff0000"&gt;Width&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;50&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;Height&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;50&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
       &lt;/font&gt;&lt;font color="#ff0000"&gt;Fill&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;Gray&lt;/font&gt;"&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;MouseLeftButtonDown&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;MyMouseLeftButtonDown&lt;/font&gt;"&lt;font color="#0000ff"&gt; /&amp;gt;
 &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;TextBlock&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;x:Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;MyText&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
       &lt;/font&gt;&lt;font color="#ff0000"&gt;Text&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;Click either rectangle or me&lt;/font&gt;"&lt;font color="#0000ff"&gt; 
       &lt;/font&gt;&lt;font color="#ff0000"&gt;MouseLeftButtonDown&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;"&lt;font color="#0000ff"&gt;MyMouseLeftButtonDown&lt;/font&gt;"&lt;font color="#0000ff"&gt; /&amp;gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Canvas&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;And my code behind &lt;em&gt;Page.xaml.cs&lt;/em&gt; contains following code:&lt;/p&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Windows.Controls;

&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; MySilverLight
{
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;partial&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;Page&lt;/font&gt; : &lt;font color="#2b91af"&gt;Canvas
&lt;/font&gt;  {
    &lt;font color="#2b91af"&gt;DateTime&lt;/font&gt; started = &lt;font color="#2b91af"&gt;DateTime&lt;/font&gt;.Now;

    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; Page_Loaded(&lt;font color="#0000ff"&gt;object&lt;/font&gt; o, &lt;font color="#2b91af"&gt;EventArgs&lt;/font&gt; e)
    {
      &lt;font color="#008000"&gt;// Required to initialize variables
&lt;/font&gt;      InitializeComponent();
    }

    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; MyMouseLeftButtonDown(&lt;font color="#0000ff"&gt;object&lt;/font&gt; o, &lt;font color="#2b91af"&gt;EventArgs&lt;/font&gt; e)
    {
      &lt;font color="#0000ff"&gt;string&lt;/font&gt; runningTime = (&lt;font color="#2b91af"&gt;DateTime&lt;/font&gt;.Now - started).TotalSeconds.ToString(&lt;font color="#a31515"&gt;"F2"&lt;/font&gt;);
      System.Windows.Shapes.&lt;font color="#2b91af"&gt;Rectangle&lt;/font&gt; rectangle = o &lt;font color="#0000ff"&gt;as&lt;/font&gt; System.Windows.Shapes.&lt;font color="#2b91af"&gt;Rectangle&lt;/font&gt;;
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (rectangle != &lt;font color="#0000ff"&gt;null&lt;/font&gt;)
      {
        MyRectangle.Opacity = 1;
        MyText.Text = &lt;font color="#a31515"&gt;"You clicked rectangle! Application has been running for "&lt;/font&gt; + 
          runningTime + &lt;font color="#a31515"&gt;" seconds."&lt;/font&gt;;
      }

      System.Windows.Controls.&lt;font color="#2b91af"&gt;TextBlock&lt;/font&gt; textBlock = o &lt;font color="#0000ff"&gt;as&lt;/font&gt; System.Windows.Controls.&lt;font color="#2b91af"&gt;TextBlock&lt;/font&gt;;
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (textBlock != &lt;font color="#0000ff"&gt;null&lt;/font&gt;)
      {
        MyRectangle.Opacity = MyRectangle.Opacity * 0.8;
        MyText.Text = &lt;font color="#a31515"&gt;"You clicked text block! Rectangle is fading away..."&lt;/font&gt;;
      }
    }
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Now you're probably eager to know what our application actually does :-) Here is our application just after request:&lt;/p&gt;
&lt;p&gt;&lt;img height="393" alt="SilverLight1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/SilverLight1_3.png" width="501" border="0"&gt; &lt;/p&gt;
&lt;p&gt;And if user clicks the rectangle...&lt;/p&gt;
&lt;p&gt;&lt;img height="159" alt="SilverLight2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/SilverLight2_945827d5-a39a-404d-9481-77b3e4a0b6c6.png" width="570" border="0"&gt; &lt;/p&gt;
&lt;p&gt;If user clicks the text...&lt;/p&gt;
&lt;p&gt;&lt;img height="158" alt="SilverLight3" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Cre.1applicationsforSharePointwithVS2008_6AC4/SilverLight3_794d2597-a3ab-4992-bf22-ab6fe394d542.png" width="414" border="0"&gt; &lt;/p&gt;
&lt;p&gt;Now we have working development environment so that we could build ant test Silverlight 1.1 applications and host them in SharePoint. Here are the steps so that you can (try :-) to do it yourself.&lt;/p&gt;
&lt;p&gt;1) Create new Silverlight project in VS2008&lt;br&gt;2) Code :-)&lt;br&gt;3) Build your solution&lt;br&gt;4) Copy contents of &lt;em&gt;ClientBin\*.*&lt;/em&gt; to the SharePoint &lt;em&gt;_LAYOUTS\ClientBin&lt;/em&gt; folder&lt;br&gt;5) Copy &lt;em&gt;*.xaml&lt;/em&gt; files from your project to the SharePoint &lt;em&gt;Silverlight &lt;/em&gt;folder (&lt;strong&gt;Note: &lt;/strong&gt;you need to verify correct path in &lt;em&gt;x:Class&lt;/em&gt;! See my &lt;em&gt;Page.xaml&lt;/em&gt; and line 5 in source)&lt;br&gt;6) Create page that uses Silverlight web part and select your newly created XAML file&lt;/p&gt;
&lt;p&gt;&lt;br&gt;Here was my small intro to Silverlight 1.1 with SharePoint. In this example I just used static &lt;em&gt;.xaml&lt;/em&gt; files sitting in file system in order to make everything as simple as possible... I just wanted to demo how you can start experimenting with this combination. This can be extended and improved in many different ways and I'll probably come back to those in my future posts. &lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6809950" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>External datasource (SharePoint list) and Forms Server</title><link>http://blogs.msdn.com/jannemattila/archive/2007/12/11/external-datasource-sharepoint-list-and-forms-server.aspx</link><pubDate>Tue, 11 Dec 2007 13:32:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6733592</guid><dc:creator>jannemattila</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/6733592.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=6733592</wfw:commentRss><description>&lt;p&gt;If you have following setup...&lt;/p&gt; &lt;ul&gt; &lt;li&gt;You need to create InfoPath Form that you're going to use in Forms Server (=Browser compatible)  &lt;li&gt;Your form contains &lt;em&gt;external data source&lt;/em&gt; to SharePoint list  &lt;li&gt;Data from the list needs to be in certain order in your form (in drop-down list box)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;...you'll have issue because your items will be sorted in the order which they have been created. Underlying reason for that is the fact that Forms Server uses SharePoint object model to retrieve the items. So if you need other sort criteria then I suggest you to create your own custom Web Service that then returns the list in correct order. This is actually good in architectural sense since this gives you extra layer for business logic. And I really recommend you do that. See my previous posts for more information: &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/10/25/from-infopath-to-database-via-web-service.aspx" target="_blank"&gt;From InfoPath to Database via Web Service&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/09/26/adding-own-custom-web-service-to-sharepoint.aspx" target="_blank"&gt;Adding own custom web service to SharePoint&lt;/a&gt;.&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6733592" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/InfoPath/default.aspx">InfoPath</category></item><item><title>Use dynamically created InfoPath form instance to pre-fill form</title><link>http://blogs.msdn.com/jannemattila/archive/2007/11/08/use-dynamically-created-infopath-form-instance-to-pre-fill-form.aspx</link><pubDate>Thu, 08 Nov 2007 01:05:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5970023</guid><dc:creator>jannemattila</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/5970023.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=5970023</wfw:commentRss><description>&lt;p&gt;If you want to pre-fill InfoPath form before user gets his/her hands to it... you have two ways to do that:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Call Web Services from InfoPath&lt;/li&gt; &lt;ul&gt; &lt;li&gt;It normally takes quite long&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Dynamically create InfoPath form instance&lt;/li&gt; &lt;ul&gt; &lt;li&gt;Fast and there isn't any limitations where to get data&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt; &lt;p&gt;Both methods have been mentioned many times in different sites but I still decided to create a demo about the "&lt;em&gt;Dynamically create InfoPath form instance&lt;/em&gt;"&lt;em&gt; &lt;/em&gt;to make this crystal clear... and give some code to get you started on this if you're interested.&lt;/p&gt; &lt;p&gt;So I created really simple InfoPath &lt;em&gt;Request Form&lt;/em&gt;:&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:b4737aab-5de5-423c-8559-ca8025ffe301" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5969299/original.aspx" alt="" style="width:652px; height:416px;" /&gt;&lt;/div&gt; &lt;p&gt;I added submit rule to the button (I just used fixed url for the form library).&lt;/p&gt; &lt;p&gt;Then I created following UI for my solution:&lt;/p&gt; &lt;p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:db8ffd0b-2dec-4e19-a3f1-821396ba9caa" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5969455/original.aspx" alt="" style="width:453px; height:464px;" /&gt;&lt;/div&gt;&lt;/p&gt; &lt;p&gt;Here is the code behind the astonishing UI (a.k.a. button inside web part):&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Runtime.InteropServices;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web.UI;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web.UI.WebControls.WebParts;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; Microsoft.SharePoint;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web.UI.WebControls;

&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; InfoPath_Creator
{
  [&lt;font color="#2b91af"&gt;Guid&lt;/font&gt;(&lt;font color="#a31515"&gt;"16ba4e60-d230-45d3-9966-da959d20a90b"&lt;/font&gt;)]
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;InfoPath_Creator&lt;/font&gt; : System.Web.UI.WebControls.WebParts.&lt;font color="#2b91af"&gt;WebPart
&lt;/font&gt;  {
    &lt;font color="#0000ff"&gt;public&lt;/font&gt; InfoPath_Creator()
    {
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.ExportMode = &lt;font color="#2b91af"&gt;WebPartExportMode&lt;/font&gt;.All;
    }

    &lt;font color="#0000ff"&gt;protected&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; CreateChildControls()
    {
      Controls.Clear();
      &lt;font color="#0000ff"&gt;base&lt;/font&gt;.CreateChildControls();
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.ChildControlsCreated = &lt;font color="#0000ff"&gt;true&lt;/font&gt;;

      &lt;font color="#2b91af"&gt;Button&lt;/font&gt; createRequestForm = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;Button&lt;/font&gt;();
      createRequestForm.Text = &lt;font color="#a31515"&gt;"Create request"&lt;/font&gt;;
      &lt;font color="#0000ff"&gt;string&lt;/font&gt; url = &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Request.Url.ToString();
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (url.IndexOf(&lt;font color="#a31515"&gt;'?'&lt;/font&gt;) == -1)
      {
        url += &lt;font color="#a31515"&gt;"?"&lt;/font&gt;;
      }
      &lt;font color="#0000ff"&gt;else
&lt;/font&gt;      {
        url += &lt;font color="#a31515"&gt;"&amp;amp;"&lt;/font&gt;;
      }
      url += &lt;font color="#a31515"&gt;"CreateRequest=true"&lt;/font&gt;;

      createRequestForm.OnClientClick = &lt;font color="#a31515"&gt;"document.location.href='"&lt;/font&gt; + url + &lt;font color="#a31515"&gt;"'; return false;"&lt;/font&gt;;
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Controls.Add(createRequestForm);
    }

    &lt;font color="#0000ff"&gt;protected&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; Render(&lt;font color="#2b91af"&gt;HtmlTextWriter&lt;/font&gt; writer)
    {
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.RenderChildren(writer);

      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (&lt;font color="#0000ff"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#a31515"&gt;"CreateRequest"&lt;/font&gt;]) == &lt;font color="#0000ff"&gt;false&lt;/font&gt;)
      {
        &lt;font color="#0000ff"&gt;string&lt;/font&gt; requestType = &lt;font color="#a31515"&gt;"Request for dynamic request forms"&lt;/font&gt;;
        &lt;font color="#0000ff"&gt;string&lt;/font&gt; requestTitle = &lt;font color="#a31515"&gt;"My dynamically created request"&lt;/font&gt;;
        &lt;font color="#0000ff"&gt;string&lt;/font&gt; estimatedCost = &lt;font color="#a31515"&gt;"123"&lt;/font&gt;;
        &lt;font color="#0000ff"&gt;string&lt;/font&gt; user = &lt;font color="#2b91af"&gt;SPContext&lt;/font&gt;.Current.Web.CurrentUser.Name;
        &lt;font color="#0000ff"&gt;string&lt;/font&gt; costCenter = &lt;font color="#a31515"&gt;"999888777"&lt;/font&gt;; &lt;font color="#008000"&gt;// TODO: get cost center from UserProfile
&lt;/font&gt;        &lt;font color="#0000ff"&gt;int&lt;/font&gt; classification = 54321;

        &lt;font color="#0000ff"&gt;string&lt;/font&gt; xml = &lt;font color="#a31515"&gt;"&amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&amp;gt;"&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"&amp;lt;?mso-infoPathSolution solutionVersion=\"1.0.0.8\" productVersion=\"12.0.0\" "&lt;/font&gt; + 
          &lt;font color="#a31515"&gt;"PIVersion=\"1.0.0.0\" href=\""&lt;/font&gt; + 
          &lt;font color="#a31515"&gt;"http://demo1:1000/PressReleases/Request%20forms/Forms/template.xsn\" "&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"name=\"urn:schemas-microsoft-com:office:infopath:"&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"Request-forms:-myXSD-2007-11-07T19-32-12\" ?&amp;gt;"&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"&amp;lt;?mso-application progid=\"InfoPath.Document\" "&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"versionProgid=\"InfoPath.Document.2\"?&amp;gt;"&lt;/font&gt; + 
          &lt;font color="#a31515"&gt;"&amp;lt;my:myFields xmlns:my=\""&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-11-07T19:32:12\" "&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"xml:lang=\"en-us\"&amp;gt;"&lt;/font&gt; +
          &lt;font color="#008000"&gt;// Here I fill the fields:
&lt;/font&gt;          &lt;font color="#a31515"&gt;"&amp;lt;my:RequestType&amp;gt;"&lt;/font&gt; + requestType + &lt;font color="#a31515"&gt;"&amp;lt;/my:RequestType&amp;gt;"&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"&amp;lt;my:RequestTitle&amp;gt;"&lt;/font&gt; + requestTitle + &lt;font color="#a31515"&gt;"&amp;lt;/my:RequestTitle&amp;gt;"&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"&amp;lt;my:EstimatedCost&amp;gt;"&lt;/font&gt; + estimatedCost + &lt;font color="#a31515"&gt;"&amp;lt;/my:EstimatedCost&amp;gt;"&lt;/font&gt; + 
          &lt;font color="#a31515"&gt;"&amp;lt;my:User&amp;gt;"&lt;/font&gt; + user+ &lt;font color="#a31515"&gt;"&amp;lt;/my:User&amp;gt;"&lt;/font&gt; + 
          &lt;font color="#a31515"&gt;"&amp;lt;my:CostCenter&amp;gt;"&lt;/font&gt; + costCenter + &lt;font color="#a31515"&gt;"&amp;lt;/my:CostCenter&amp;gt;"&lt;/font&gt; + 
          &lt;font color="#a31515"&gt;"&amp;lt;my:Classification xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"&amp;gt;"&lt;/font&gt; + 
          classification + &lt;font color="#a31515"&gt;"&amp;lt;/my:Classification&amp;gt;"&lt;/font&gt; +
          &lt;font color="#a31515"&gt;"&amp;lt;/my:myFields&amp;gt;"&lt;/font&gt;;
        &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Response.Clear();
        &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Response.AppendHeader(&lt;font color="#a31515"&gt;"Content-Disposition"&lt;/font&gt;, &lt;font color="#a31515"&gt;"attachment;filename=Request-"&lt;/font&gt; + 
          &lt;font color="#2b91af"&gt;DateTime&lt;/font&gt;.Now.ToString(&lt;font color="#a31515"&gt;"yyyy-MM-dd-HH-mm-ss"&lt;/font&gt;) );
        &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Response.ContentType = &lt;font color="#a31515"&gt;"application/ms-infopath.xml"&lt;/font&gt;;
        &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Response.Write(xml);
        &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Response.Flush();
        &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Page.Response.End();
      }
    }
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;In lines 54 to 73 I created the XML for the form (it looks like real mess and I'm sorry about it!). Most important stuff happens between lines 66 and 72 where the actual field values are stored. Of course you could use some magic code to get the correct values to the variable at lines 47 - 52. And you can also probably see the URL of the XSN file (line 57) and as well as the namespace (line 63). It looks like this when user clicks the &lt;em&gt;Create request&lt;/em&gt; button:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:7ee70f3a-3596-43d8-8309-960bd27ae3db" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5969640/original.aspx" alt="" style="width:641px; height:359px;" /&gt;&lt;/div&gt;
&lt;p&gt;And when user presses the button in InfoPath the form data is submitted to the form library:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:43186b63-de5e-4c2d-9736-19c2a85f76ae" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5969749/original.aspx" alt="" style="width:658px; height:183px;" /&gt;&lt;/div&gt;
&lt;p&gt;So hopefully after this post you'll remember that this method is powerful (and not the messy XML :-) if you want fill InfoPath with data. You have much more possibilities than just simple web service request in InfoPath.&lt;/p&gt;
&lt;p&gt;By the way... Why do I always end up with titles with word "dynamic*" in it :-) (see my previous post for example)&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5970023" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/InfoPath/default.aspx">InfoPath</category></item><item><title>Dynamically create static Excel files for Excel Service</title><link>http://blogs.msdn.com/jannemattila/archive/2007/11/06/dynamically-create-static-excel-files-for-excel-service.aspx</link><pubDate>Tue, 06 Nov 2007 20:07:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5939871</guid><dc:creator>jannemattila</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/5939871.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=5939871</wfw:commentRss><description>&lt;p&gt;Excel Services is pretty nice for displaying Excel files over the network. But if you're developing Excel Services solution for the first time you might first think of the limitations or something that forces you to build your overall solution in certain way. So I thought I'll write little bit about my idea about creating dynamically static Excel files. This might be something that you could be interested in... or not :-) It of course depends on the solution that you need to build. I just want to give you few ideas that you can use in your own projects. Okay here we go!&lt;/p&gt; &lt;h3&gt;&lt;/h3&gt; &lt;h3&gt;We want...&lt;/h3&gt; &lt;ol&gt; &lt;li&gt;...to use 2 different languages (Finnish and English)  &lt;li&gt;...have static texts in Excel that needs to be translatable  &lt;li&gt;...use pivottables  &lt;li&gt;...export data into .xlsx and to .csv (and possibly to some other formats as well)  &lt;ul&gt; &lt;li&gt;And the end user cannot see any formulas in their exported files&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;...filter the data from UI &lt;ul&gt; &lt;li&gt;Translation for that: We need to pass parameters to the database query&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;...have easily maintainable system (=minimize the amount of Excels)  &lt;li&gt;...flexible solution. So if we later want more complex scenarios this needs to be supported in your solution.  &lt;li&gt;...performance performance performance (but no extra costs!)  &lt;ul&gt; &lt;li&gt;But we only update the incoming data quite rarely&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Okay... list is quite long and I need to discuss a little bit about those demands. &lt;/p&gt; &lt;p&gt;1 to 3) Supporting more than one language can be issue if your data contains texts that needs to be translated. Also pivottable column names, captions and total captions needs to be translated. So translating static texts is easy compared to that :-)&lt;/p&gt; &lt;p&gt;4) Exporting to .xlsx is easy. Just use Excel Services API and retrieve "snapshot" and you're good to go. But if you want to convert it to other formats then you need to do some extra work.&lt;/p&gt; &lt;p&gt;5) You can use filtering but if you think of 8) you just can't do filtering of 2 million rows if you just want to view 50 rows... that would kill the performance. So since you need to think of performance you probably want to pass parameters to your database queries. If plan to get your relational data into your Excel using Office Database Connection (ODC)&amp;nbsp; you cannot unfortunately use parameters since querytext will be "&lt;em&gt;hardcoded&lt;/em&gt;" into the ODC. Of course you can achieve that with multiple ODC files but it could create mess. You can store those in Data Connection Library (DCL) to ease up the maintenance pain but still it's quite challenging to do that (=my personal opinion). And if you then think of the 6) you don't want to create maintenance hell. And of course if it gets too complicated you would most likely have issues with ODC approach. But if you use OLAP you could manage with only one ODC.&lt;/p&gt; &lt;p&gt;6) You don't want to have 1,5 million different files and then update them manually? Okay... I'll get the picture.&lt;/p&gt; &lt;p&gt;7) I know that predicting future is hard so let's create solution that is flexible enough so that you can extend it in many ways. I don't want to give limitations to your future needs.&lt;/p&gt; &lt;p&gt;8) So you don't want to buy 5 new servers with lot of processors? What about memory then... it's cheap? So that's okay... let's try to create as static files as we only can. This way we can use "&lt;em&gt;memory over CPU&lt;/em&gt;" approach as much as possible. And creating stuff in cache before users are going to use the system would be nice.&lt;/p&gt; &lt;p&gt;I'm ready to go to next phase and show you my example that I have created.&lt;/p&gt; &lt;h3&gt;Implementation of my solution&lt;/h3&gt; &lt;p&gt;Phases:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Create database for the example  &lt;li&gt;Create template Excel file  &lt;ul&gt; &lt;li&gt;This is then used to create the "static copy instance"&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Create SharePoint structure for the demo  &lt;li&gt;Create custom web part that hosts EWA and fills the other requirements as well  &lt;ul&gt; &lt;li&gt;Exports to different file formats  &lt;li&gt;Filter the query from UI  &lt;li&gt;Translate texts that are needed in order to get the file in users native language&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt; &lt;h4&gt;&lt;strong&gt;1. Create database for the example&lt;/strong&gt;&lt;/h4&gt; &lt;p&gt;In my example I'll use legendary AdventureWorks database :-) (I know that for some developers this itself will cause some hatred towards me ;-)&lt;/p&gt; &lt;p&gt;I did minor changes to the AdventureWorks data since I want my demo to support English and Finnish. I modified French culture to be Finnish culture and then modified the texts in description to be example same as the name (so that I'll can demonstrate the translations in database layer) (Note: I didnt' change the &lt;em&gt;ProductModel&lt;/em&gt; translation since I want to "translate" it in my code). &lt;/p&gt; &lt;p&gt;My plans is to demonstrate product data. Here's an example of the data:&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:89098b14-74fc-43bd-b0c9-4e4230bce981" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5831110/original.aspx" alt="" style="width:580px; height:168px;" /&gt;&lt;/div&gt; &lt;p&gt;From that data you can easily see that I'm going to use culture info to get the correct data to my Excel. Of course you could create your own SQL/stored procs to handle translations as you wish. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;2. Create template Excel&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Now I'm going to create Excel that uses previously modified data. Since my plan is to dynamically fill the Excel with data I'm just going to create "&lt;em&gt;almost empty template&lt;/em&gt;" that will be placeholder for the real data. Here are screenshots from my &lt;em&gt;MyEWA.xlsx&lt;/em&gt; Excel file:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:a62d8358-04c7-47e6-985b-8130ac82be19" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5919972/original.aspx" alt="" style="width:497px; height:395px;" /&gt;&lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;Display&lt;/em&gt;-sheet has static text in &lt;em&gt;A2&lt;/em&gt; and then it has Pivottable that retrieves data from the &lt;em&gt;Data&lt;/em&gt;. If you're really sharp you probably noticed that row 5 is missing from the &lt;em&gt;Display&lt;/em&gt;-sheet... I'll come to that later.&lt;br&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:95af23cd-71ad-4ede-bf55-f2732c1708e8" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5920286/original.aspx" alt="" style="width:496px; height:395px;" /&gt;&lt;/div&gt;&lt;br&gt;&lt;em&gt;Data&lt;/em&gt;-sheet contains Header row and then it contains 1 data row. This data row can been seen from the pivottable in the &lt;em&gt;Display&lt;/em&gt;-sheet.  &lt;p&gt;&lt;/p&gt; &lt;p&gt;Third sheet is &lt;em&gt;Parameters&lt;/em&gt; and in this example I'll only use it to pass &lt;em&gt;Culture&lt;/em&gt; to the Excel:&lt;br&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:31a23842-fe5c-4018-8c24-add68a395b62" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5920590/original.aspx" alt="" style="width:497px; height:392px;" /&gt;&lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;So if we now take closer look at the &lt;em&gt;Display&lt;/em&gt;-sheet and see the formula in cell &lt;em&gt;A2&lt;/em&gt;:&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:f7f20a7d-c44c-46b2-9c91-1a16f76b6755" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5920691/original.aspx" alt="" style="width:796px; height:118px;" /&gt;&lt;/div&gt; &lt;p&gt;&lt;em&gt;A2&lt;/em&gt; cell contains following formula:&lt;/p&gt; &lt;p&gt;&lt;em&gt;=IF(Parameters!B1="en-US";"Here is report about products.";"Tässä on raportti tuotteista")&lt;/em&gt;&lt;/p&gt; &lt;p&gt;It's pretty easy to understand that if the &lt;em&gt;B1 &lt;/em&gt;cell in &lt;em&gt;Parameters&lt;/em&gt;-sheet is set to &lt;em&gt;en-US&lt;/em&gt; then the text will be "&lt;em&gt;Here is report about products&lt;/em&gt;"&lt;em&gt;.&lt;/em&gt; and if it isn't then "&lt;em&gt;Tässä on raportti tuotteista&lt;/em&gt;" text will appear in the cell (latter text is same as the English one but in Finnish :-). By now probably everybody knows already that we're going to change the value in &lt;em&gt;Parameters!B1&lt;/em&gt; dynamically... and use it to translate the static texts inside Excel into correct language. &lt;/p&gt; &lt;p&gt;This same can be achieved if you dynamically copy text over specific cells. I have example of that in my code but it's commented because I didn't use it in my solution. But if you need to check this approach you can create new sheet i.e. &lt;em&gt;Translations&lt;/em&gt; and have three columns &lt;em&gt;Location, Text in fi-FI&lt;/em&gt; and &lt;em&gt;Text in en-US.&lt;/em&gt; And then dynamically go through those translations and copy text to correct location i.e. &lt;em&gt;Data!A5&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;3. Create SharePoint structure for the demo&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;SharePoint site structure is following in my demo (in your case you can have whatever names... I just used culturenames to make this as simple as possible):&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Example portal  &lt;ul&gt; &lt;li&gt;en-US:  &lt;ul&gt; &lt;li&gt;default.aspx  &lt;li&gt;MyEWA.aspx&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;fi-FI  &lt;ul&gt; &lt;li&gt;default.aspx  &lt;li&gt;MunEWA.aspx&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Obviously &lt;em&gt;en-US&lt;/em&gt; is site that has regional settings (Site settings-&amp;gt;Site administration: Regional settings) set to &lt;em&gt;English&lt;/em&gt; locale:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:805ecaa4-a374-48b1-a2a0-5b2db8470a78" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5921172/original.aspx" alt="" style="width:527px; height:169px;" /&gt;&lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;And &lt;em&gt;fi-FI&lt;/em&gt; site is set to &lt;em&gt;Finnish &lt;/em&gt;locale.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;4. Create custom web part that hosts EWA and fills the other requirements as well&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Now we're ready to show the user interface for our solution. My solution is &lt;em&gt;MyEWA&lt;/em&gt; web part that contains all the necessary controls and functionality this solution needs. As always my I'll cut short in the UI implementation. I'll just add few buttons and dropdown but no fancy look &amp;amp; feel. &lt;/p&gt; &lt;p&gt;UI in &lt;em&gt;MyEWA.aspx&lt;/em&gt;:&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:e25a8f6c-c5ba-4302-93fb-1ff60be2ca08" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5929401/original.aspx" alt="" style="width:675px; height:368px;" /&gt;&lt;/div&gt; &lt;p&gt;UI in &lt;em&gt;MunEWA.aspx&lt;/em&gt;:&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:99e08fef-e869-4d4f-afb0-fd816a07ec62" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5929362/original.aspx" alt="" style="width:634px; height:375px;" /&gt;&lt;/div&gt; &lt;p&gt;(Note: Anyone who understands Finnish may laugh at my translations since I translated them smile in my face :-)&lt;/p&gt; &lt;p&gt;UI is pretty easy and straight forward: 1 dropdown to select product (=this is used as filter criteria in DB request) and 2 export buttons (Excel and CSV). If user would press &lt;em&gt;Export Excel &lt;/em&gt;output would be something like this:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:39392043-6453-4fd4-a108-f154c1b4d53c" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5929543/original.aspx" alt="" style="width:331px; height:556px;" /&gt;&lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;And if user would press &lt;em&gt;Vie Exceliin&lt;/em&gt; output would be something like this:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:776c3d78-7dba-4702-88e2-a0a11b6a0fd9" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5929558/original.aspx" alt="" style="width:389px; height:540px;" /&gt;&lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;Both of those export files are &lt;em&gt;Snapshots&lt;/em&gt; (=they don't contain formulas just data).&lt;/p&gt; &lt;p&gt;If user would use &lt;em&gt;Vie CSV&lt;/em&gt; -button (=Export to CSV) it would look something like this:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:694d5e5d-4b49-46a4-b851-792c37b72e00" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5930699/original.aspx" alt="" style="width:349px; height:540px;" /&gt;&lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;(Note: You can see [again!] empty row 5... but I'll explain reason for that soon)&lt;/p&gt; &lt;p&gt;Now I think we're ready to start reading some code. Just to remind you that I have put all the functionality into this one .cs file but &lt;u&gt;in real life you don't do that&lt;/u&gt;! You refactor this kind of approach into several classes so that it is more maintainable. &lt;u&gt;My "one file approach" is for demonstration purposes only&lt;/u&gt;. Also improving error handling is out of scope of this demo. Access rights is also something that needs to be solved since that process needs to write files to file system. Of course that can be solved with &lt;em&gt;impersonation&lt;/em&gt; but anyway that needs to be taken into account. But finally here's the code:&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="blue"&gt;using&lt;/font&gt; System;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Runtime.InteropServices;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Web.UI;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Web.UI.WebControls.WebParts;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Xml.Serialization;
&lt;font color="blue"&gt;using&lt;/font&gt; Microsoft.SharePoint;
&lt;font color="blue"&gt;using&lt;/font&gt; Microsoft.Office.Excel.WebUI;
&lt;font color="blue"&gt;using&lt;/font&gt; System.IO;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Threading;
&lt;font color="blue"&gt;using&lt;/font&gt; Microsoft.Office.Excel.Server.WebServices;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Web.UI.WebControls;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Web;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Resources;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Data;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Data.SqlClient;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Text;

&lt;font color="blue"&gt;namespace&lt;/font&gt; MyEWA
{
  [&lt;font color="#409090"&gt;Guid&lt;/font&gt;(&lt;font color="#aa2000"&gt;"97db47dc-7f23-4975-b246-26c237e74243"&lt;/font&gt;)]
  &lt;font color="blue"&gt;public&lt;/font&gt; &lt;font color="blue"&gt;class&lt;/font&gt; &lt;font color="#008080"&gt;MyEWA&lt;/font&gt; : System.Web.UI.WebControls.WebParts.&lt;font color="#008080"&gt;WebPart&lt;/font&gt;
  {
    &lt;font color="#008080"&gt;ExcelWebRenderer&lt;/font&gt; ewa;
    &lt;font color="#008080"&gt;DropDownList&lt;/font&gt; productsList;
    &lt;font color="#008080"&gt;Button&lt;/font&gt; exportSnapshot;
    &lt;font color="#008080"&gt;Button&lt;/font&gt; exportSnapshotCSV;
    &lt;font color="blue"&gt;string&lt;/font&gt; xlFileWithoutPath;
    &lt;font color="blue"&gt;string&lt;/font&gt; xlFile;
    &lt;font color="blue"&gt;string&lt;/font&gt; xlPath;
    &lt;font color="blue"&gt;string&lt;/font&gt; xlStorageDirectory;
    &lt;font color="blue"&gt;string&lt;/font&gt; xlTemplateFile;
    &lt;font color="blue"&gt;string&lt;/font&gt; culture;

    &lt;font color="blue"&gt;public&lt;/font&gt; MyEWA()
    {
      &lt;font color="blue"&gt;this&lt;/font&gt;.ExportMode = &lt;font color="#008080"&gt;WebPartExportMode&lt;/font&gt;.All;
    }

    &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="blue"&gt;string&lt;/font&gt; ConnectionString
    {
      &lt;font color="#0000ff"&gt;get&lt;/font&gt;
      {
        &lt;font color="green"&gt;// ERROR: don't ever store connection string in your class!
&lt;/font&gt;        &lt;font color="blue"&gt;return&lt;/font&gt; &lt;font color="#aa2000"&gt;"..."&lt;/font&gt;;
      }
    }

    &lt;font color="green"&gt;// TODO: refactor this into separate class!
&lt;/font&gt;    &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="#008080"&gt;DataTable&lt;/font&gt; GetExcelData(&lt;font color="blue"&gt;string&lt;/font&gt; product, &lt;font color="blue"&gt;string&lt;/font&gt; culture)
    {
      &lt;font color="blue"&gt;using&lt;/font&gt; (&lt;font color="#008080"&gt;SqlConnection&lt;/font&gt; conn = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;SqlConnection&lt;/font&gt;(&lt;font color="blue"&gt;this&lt;/font&gt;.ConnectionString))
      {
        &lt;font color="green"&gt;// If you have translations inside your database you can pass on the culture to the db:
&lt;/font&gt;        &lt;font color="#008080"&gt;SqlCommand&lt;/font&gt; cmd = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;SqlCommand&lt;/font&gt;(
          &lt;font color="#aa2000"&gt;"SELECT Production.vProductAndDescription.ProductModel, "&lt;/font&gt; +
          &lt;font color="#aa2000"&gt;"Production.vProductAndDescription.Description AS Product, "&lt;/font&gt; +
          &lt;font color="#aa2000"&gt;"Production.Product.ListPrice AS Price "&lt;/font&gt; +
          &lt;font color="#aa2000"&gt;"FROM Production.vProductAndDescription INNER JOIN "&lt;/font&gt; +
          &lt;font color="#aa2000"&gt;"Production.Product ON "&lt;/font&gt; +
          &lt;font color="#aa2000"&gt;"Production.vProductAndDescription.ProductID = Production.Product.ProductID AND "&lt;/font&gt; +
          &lt;font color="#aa2000"&gt;"Production.vProductAndDescription.ProductModel LIKE @Product+'%' AND "&lt;/font&gt; +
          &lt;font color="#aa2000"&gt;"Production.vProductAndDescription.CultureID LIKE @Culture+'%'"&lt;/font&gt;, conn);

        cmd.Parameters.AddWithValue(&lt;font color="#aa2000"&gt;"@Product"&lt;/font&gt;, product);
        cmd.Parameters.AddWithValue(&lt;font color="#aa2000"&gt;"@Culture"&lt;/font&gt;, culture.Substring(0,2));

        &lt;font color="#008080"&gt;SqlDataAdapter&lt;/font&gt; adapter = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;SqlDataAdapter&lt;/font&gt;(cmd);
        &lt;font color="#008080"&gt;DataSet&lt;/font&gt; ds = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;DataSet&lt;/font&gt;();
        adapter.Fill(ds);

        &lt;font color="blue"&gt;return&lt;/font&gt; ds.Tables[0];
      }
    }

    &lt;font color="blue"&gt;protected&lt;/font&gt; &lt;font color="blue"&gt;override&lt;/font&gt; &lt;font color="blue"&gt;void&lt;/font&gt; CreateChildControls()
    {
      &lt;font color="green"&gt;// Get default locale from current site:
&lt;/font&gt;      &lt;font color="green"&gt;// (Note: this can be changed from site settings)
&lt;/font&gt;      culture = SPContext.Current.Web.Locale.ToString();
      &lt;font color="blue"&gt;if&lt;/font&gt; (&lt;font color="blue"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Language"&lt;/font&gt;&lt;/font&gt;]) == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        &lt;font color="green"&gt;// I'll give way to change the language on the fly:
&lt;/font&gt;        culture = &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Language"&lt;/font&gt;&lt;/font&gt;];

        &lt;font color="#008080"&gt;Thread&lt;/font&gt;.CurrentThread.CurrentCulture = &lt;font color="blue"&gt;new&lt;/font&gt; System.Globalization.&lt;font color="#008080"&gt;CultureInfo&lt;/font&gt;(culture);
        &lt;font color="#008080"&gt;Thread&lt;/font&gt;.CurrentThread.CurrentUICulture = &lt;font color="blue"&gt;new&lt;/font&gt; System.Globalization.&lt;font color="#008080"&gt;CultureInfo&lt;/font&gt;(culture); 
      }

      Controls.Clear();
      &lt;font color="blue"&gt;base&lt;/font&gt;.CreateChildControls();
      &lt;font color="blue"&gt;this&lt;/font&gt;.ChildControlsCreated = &lt;font color="blue"&gt;true&lt;/font&gt;;

      &lt;font color="#008080"&gt;Label&lt;/font&gt; productLabel = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;Label&lt;/font&gt;();
      productLabel.Text = &lt;font color="#008080"&gt;MyEWAResources&lt;/font&gt;.ProductList_Select;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Controls.Add(productLabel);

      productsList = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;DropDownList&lt;/font&gt;();
      productsList.ID = &lt;font color="#aa2000"&gt;"productsList"&lt;/font&gt;;
      &lt;font color="green"&gt;// TODO: get your product filter list using SQL statements
&lt;/font&gt;      &lt;font color="green"&gt;// and remember to store that in cache =&amp;gt; performance.
&lt;/font&gt;      &lt;font color="green"&gt;// Something like this:
&lt;/font&gt;      &lt;font color="green"&gt;// this.Page.Cache.Add("ProductList", ...);
&lt;/font&gt;      &lt;font color="green"&gt;// And of course you can use SqlCacheDependency if you want.
&lt;/font&gt;
      &lt;font color="green"&gt;// I'll just fill in static filters (I'm lazy!):
&lt;/font&gt;      productsList.Items.Add(&lt;font color="blue"&gt;new&lt;/font&gt; ListItem(&lt;font color="#008080"&gt;MyEWAResources&lt;/font&gt;.ProductList_Item1, &lt;font color="#aa2000"&gt;"Mountain"&lt;/font&gt;));
      productsList.Items.Add(&lt;font color="blue"&gt;new&lt;/font&gt; ListItem(&lt;font color="#008080"&gt;MyEWAResources&lt;/font&gt;.ProductList_Item2, &lt;font color="#aa2000"&gt;"Road"&lt;/font&gt;));
      productsList.Items.Add(&lt;font color="blue"&gt;new&lt;/font&gt; ListItem(&lt;font color="#008080"&gt;MyEWAResources&lt;/font&gt;.ProductList_Item3, &lt;font color="#aa2000"&gt;"HL"&lt;/font&gt;));
      productsList.AutoPostBack = &lt;font color="blue"&gt;true&lt;/font&gt;;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Controls.Add(productsList);

      &lt;font color="green"&gt;// Create some buttons:
&lt;/font&gt;      exportSnapshot = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;Button&lt;/font&gt;();
      exportSnapshot.Text = &lt;font color="#008080"&gt;MyEWAResources&lt;/font&gt;.ExportSnapshot;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Controls.Add(exportSnapshot);

      exportSnapshotCSV = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;Button&lt;/font&gt;();
      exportSnapshotCSV.Text = &lt;font color="#008080"&gt;MyEWAResources&lt;/font&gt;.ExportSnapshotCSV;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Controls.Add(exportSnapshotCSV);

      ewa = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;ExcelWebRenderer&lt;/font&gt;();
      &lt;font color="blue"&gt;this&lt;/font&gt;.Controls.Add(ewa);
    }

    &lt;font color="blue"&gt;protected&lt;/font&gt; &lt;font color="blue"&gt;override&lt;/font&gt; &lt;font color="blue"&gt;void&lt;/font&gt; OnLoad(&lt;font color="#409090"&gt;EventArgs&lt;/font&gt; e)
    {
      &lt;font color="blue"&gt;this&lt;/font&gt;.EnsureChildControls();
      &lt;font color="blue"&gt;base&lt;/font&gt;.OnLoad(e);

      &lt;font color="green"&gt;// Get values from UI:
&lt;/font&gt;      &lt;font color="blue"&gt;string&lt;/font&gt; productFilter = productsList.SelectedValue;

      &lt;font color="green"&gt;// TODO: get these values from web part properties!!!
&lt;/font&gt;      &lt;font color="green"&gt;// This is the UNC path of the Excel files:
&lt;/font&gt;      xlPath = &lt;font color="#aa2000"&gt;"//demo1/ExcelServices/xlsx";
&lt;/font&gt;      &lt;font color="green"&gt;// This is folder where static instances will be created (under previous folder)
&lt;/font&gt;      xlStorageDirectory = &lt;font color="#aa2000"&gt;"Storage/"&lt;/font&gt;;
      &lt;font color="green"&gt;// This name of the static Excel file:
&lt;/font&gt;      xlFileWithoutPath = &lt;font color="blue"&gt;string&lt;/font&gt;.Format(&lt;font color="#aa2000"&gt;"MyEWA-{0}-{1}.xlsx"&lt;/font&gt;, culture, productFilter);
      &lt;font color="green"&gt;// This name of the template Excel file
&lt;/font&gt;      &lt;font color="green"&gt;// NOTE: You should store this inside SharePoint!!!
&lt;/font&gt;      xlTemplateFile = xlPath + &lt;font color="#aa2000"&gt;"MyEWA.xlsx"&lt;/font&gt;;
      xlFile = xlPath + xlStorageDirectory + xlFileWithoutPath;

      &lt;font color="green"&gt;// Let's add Export calls to the client side of the buttons:
&lt;/font&gt;      exportSnapshot.OnClientClick = &lt;font color="blue"&gt;this&lt;/font&gt;.BuildExportScript(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"xlsx"&lt;/font&gt;&lt;/font&gt;, xlFileWithoutPath);
      exportSnapshotCSV.OnClientClick = &lt;font color="blue"&gt;this&lt;/font&gt;.BuildExportScript(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"csv"&lt;/font&gt;&lt;/font&gt;, xlFileWithoutPath);

      &lt;font color="green"&gt;// Do we need to export file? (new .aspx page for this would be good idea!)
&lt;/font&gt;      &lt;font color="blue"&gt;if&lt;/font&gt; (&lt;font color="blue"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"ExportFormat"&lt;/font&gt;&lt;/font&gt;]) == &lt;font color="blue"&gt;false&lt;/font&gt; &amp;amp;&amp;amp;
          &lt;font color="blue"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"File"&lt;/font&gt;&lt;/font&gt;]) == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        &lt;font color="green"&gt;// Yes we need to export file
&lt;/font&gt;
        &lt;font color="green"&gt;// TODO: add sanity checks for the filename
&lt;/font&gt;        xlFile = xlPath + xlStorageDirectory + &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"File"&lt;/font&gt;&lt;/font&gt;].ToString();
        &lt;font color="blue"&gt;string&lt;/font&gt; format = &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"ExportFormat"&lt;/font&gt;&lt;/font&gt;].ToString();
        &lt;font color="blue"&gt;switch&lt;/font&gt; (format)
        {
          &lt;font color="blue"&gt;case&lt;/font&gt; &lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"csv"&lt;/font&gt;&lt;/font&gt;:
            ExportSnapshotAsCSV();
            &lt;font color="blue"&gt;break&lt;/font&gt;;
          &lt;font color="blue"&gt;case&lt;/font&gt; &lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"xlsx"&lt;/font&gt;&lt;/font&gt;:
            ExportSnapshotAsExcel();
            &lt;font color="blue"&gt;break&lt;/font&gt;;
          &lt;font color="#0000ff"&gt;default&lt;/font&gt;:
            &lt;font color="blue"&gt;throw&lt;/font&gt; &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#409090"&gt;Exception&lt;/font&gt;(
              &lt;font color="blue"&gt;string&lt;/font&gt;.Format(&lt;font color="#aa2000"&gt;"Export format '{0}' not supported!"&lt;/font&gt;, format));
        }
      }

      &lt;font color="green"&gt;// Does the cache file already exists?
&lt;/font&gt;      &lt;font color="#0000ff"&gt;bool&lt;/font&gt; useCachedXlFile = &lt;font color="#008080"&gt;File&lt;/font&gt;.Exists(xlFile);
      &lt;font color="blue"&gt;if&lt;/font&gt; (useCachedXlFile == &lt;font color="blue"&gt;true&lt;/font&gt;)
      {
        &lt;font color="green"&gt;// Cache file exists but let's compare timestamps:
&lt;/font&gt;        &lt;font color="#008080"&gt;FileInfo&lt;/font&gt; src = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;FileInfo&lt;/font&gt;(xlTemplateFile);
        &lt;font color="#008080"&gt;FileInfo&lt;/font&gt; dst = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;FileInfo&lt;/font&gt;(xlFile);
        &lt;font color="blue"&gt;if&lt;/font&gt; (src.LastWriteTimeUtc &amp;gt; dst.LastWriteTimeUtc)
        {
          &lt;font color="green"&gt;// Template file is newer than cache file!
&lt;/font&gt;          useCachedXlFile = &lt;font color="blue"&gt;false&lt;/font&gt;;
        }
      }

      &lt;font color="blue"&gt;if&lt;/font&gt; (useCachedXlFile == &lt;font color="blue"&gt;true&lt;/font&gt;)
      {
        &lt;font color="green"&gt;// TODO: add your own custom logic to check that cache is still valid
&lt;/font&gt;        &lt;font color="green"&gt;// I.e. check site property bag about 'UpdateExcels' timestamp
&lt;/font&gt;      }

      &lt;font color="blue"&gt;if&lt;/font&gt; (useCachedXlFile == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        &lt;font color="green"&gt;// We need to create the cache file!
&lt;/font&gt;
        &lt;font color="green"&gt;// Let's get data to the Excel:
&lt;/font&gt;        &lt;font color="#008080"&gt;DataTable&lt;/font&gt; excelData = &lt;font color="blue"&gt;this&lt;/font&gt;.GetExcelData(productFilter, culture);
        &lt;font color="green"&gt;// In my example 'Description' field is actually already translated in the db
&lt;/font&gt;        &lt;font color="green"&gt;// so we need to translated only the 'ProductModel' in our data
&lt;/font&gt;        &lt;font color="green"&gt;// (this is here just to demonstrate that text can be translated in many 
&lt;/font&gt;        &lt;font color="green"&gt;// different layers: Excel, Code, DB etc.)
&lt;/font&gt;        &lt;font color="blue"&gt;if&lt;/font&gt; (culture.StartsWith(&lt;font color="#aa2000"&gt;"en"&lt;/font&gt;, &lt;font color="#008080"&gt;StringComparison&lt;/font&gt;.OrdinalIgnoreCase) == &lt;font color="blue"&gt;false&lt;/font&gt;)
        {
          &lt;font color="green"&gt;// This culture isn't the "original" database culture 
&lt;/font&gt;          &lt;font color="green"&gt;// so we need to translate "ProductModel" field
&lt;/font&gt;
          &lt;font color="green"&gt;// TODO: implement real translation 
&lt;/font&gt;          &lt;font color="blue"&gt;foreach&lt;/font&gt; (&lt;font color="#008080"&gt;DataRow&lt;/font&gt; row in excelData.Rows)
          {
            row[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"ProductModel"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;] = &lt;font color="#aa2000"&gt;"Suomeksi - "&lt;/font&gt; + row[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"ProductModel"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;];
            row.AcceptChanges();
          }
          excelData.AcceptChanges();
        }

        &lt;font color="blue"&gt;using&lt;/font&gt; (&lt;font color="#008080"&gt;ExcelService&lt;/font&gt; es = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;ExcelService&lt;/font&gt;())
        {
          &lt;font color="#008080"&gt;Status&lt;/font&gt;[] status;
          &lt;font color="blue"&gt;string&lt;/font&gt; sessionId = es.OpenWorkbook(xlTemplateFile, culture, culture, &lt;font color="blue"&gt;out&lt;/font&gt; status);
          &lt;font color="green"&gt;// Set culture to the parameters:
&lt;/font&gt;          es.SetCellA1(sessionId, &lt;font color="#aa2000"&gt;"Parameters"&lt;/font&gt;, &lt;font color="#aa2000"&gt;"Culture"&lt;/font&gt;, culture, &lt;font color="blue"&gt;out&lt;/font&gt; status);

          &lt;font color="green"&gt;// TODO: get your fancy data with current information:
&lt;/font&gt;          &lt;font color="blue"&gt;object&lt;/font&gt;[] excelDataArray = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="blue"&gt;object&lt;/font&gt;[excelData.Rows.Count + 1];
          &lt;font color="blue"&gt;object&lt;/font&gt;[] excelRowArray = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="blue"&gt;object&lt;/font&gt;[excelData.Columns.Count];

          &lt;font color="green"&gt;// You might think that you could change the columns of your data with following code:
&lt;/font&gt;          &lt;font color="#008000"&gt;// for (int i = 0; i &amp;lt; excelData.Columns.Count; i++)
          // {
          //   // Get correct labels for the texts:
          //   excelRowArray[i] = MyEWAResources.ResourceManager.GetString(
          //     "Column_" + excelData.Columns[i].ColumnName);
          // }
&lt;/font&gt;          &lt;font color="green"&gt;// BUT BUT BUT... You cannot change columns since Pivottable won't work after that :-(
&lt;/font&gt;
          excelDataArray[0] = excelRowArray;

          &lt;font color="green"&gt;// Fill the data with retrieved values:
&lt;/font&gt;          &lt;font color="blue"&gt;for&lt;/font&gt; (&lt;font color="blue"&gt;int&lt;/font&gt; i = 0; i &amp;lt; excelData.Rows.Count; i++)
          {
            excelRowArray = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="blue"&gt;object&lt;/font&gt;[excelData.Columns.Count];
            &lt;font color="blue"&gt;for&lt;/font&gt; (&lt;font color="blue"&gt;int&lt;/font&gt; j = 0; j &amp;lt; excelData.Columns.Count; j++)
            {
              excelRowArray[j] = excelData.Rows[i][excelData.Columns[j]];
            }
            excelDataArray[i + 1] = excelRowArray;
          }
          
          &lt;font color="#008080"&gt;RangeCoordinates&lt;/font&gt; range = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;RangeCoordinates&lt;/font&gt;();
          range.Column = 0;
          range.Row = 1;
          range.Width = excelData.Columns.Count;
          range.Height = excelData.Rows.Count + 1;

          &lt;font color="green"&gt;// Store data into Excel:
&lt;/font&gt;          es.SetRange(sessionId, &lt;font color="#aa2000"&gt;"Data"&lt;/font&gt;, range, excelDataArray, &lt;font color="blue"&gt;out&lt;/font&gt; status);

          &lt;font color="green"&gt;// You might think that you could change the Pivottable captions on the fly:
&lt;/font&gt;          &lt;font color="green"&gt;// es.SetCellA1(sessionId, "Display", "A5", "My new pivot caption", out status);
&lt;/font&gt;          &lt;font color="green"&gt;// BUT BUT BUT.. It doesn't work (=nothing happens) :-(
&lt;/font&gt;
          &lt;font color="green"&gt;// Let's refresh our datasources (=update pivottable):
&lt;/font&gt;          es.Refresh(sessionId, &lt;font color="blue"&gt;null&lt;/font&gt;, &lt;font color="blue"&gt;out&lt;/font&gt; status);

          &lt;font color="green"&gt;// Following 'block' of code can be used if you want to have
&lt;/font&gt;          &lt;font color="green"&gt;// separate sheet in your Excel file for translations:
&lt;/font&gt;          &lt;font color="green"&gt;//
&lt;/font&gt;          &lt;font color="green"&gt;//bool doneTranslations = false;
&lt;/font&gt;          &lt;font color="green"&gt;//range = new RangeCoordinates();
&lt;/font&gt;          &lt;font color="green"&gt;//range.Column = 0;
&lt;/font&gt;          &lt;font color="green"&gt;//range.Row = 1;
&lt;/font&gt;          &lt;font color="green"&gt;//range.Width = 2;
&lt;/font&gt;          &lt;font color="green"&gt;//range.Height = 10;
&lt;/font&gt;          &lt;font color="green"&gt;//while (doneTranslations == false)
&lt;/font&gt;          &lt;font color="green"&gt;//{
&lt;/font&gt;          &lt;font color="green"&gt;//  // So we get all the data from Translations-sheet and then we
&lt;/font&gt;          &lt;font color="green"&gt;//  // copy the text over to the locations defined in Excel:
&lt;/font&gt;          &lt;font color="green"&gt;//  object[] rowData = es.GetRange(sessionId, 
&lt;/font&gt;          &lt;font color="green"&gt;//    "Translations", range, false, out status);
&lt;/font&gt;          &lt;font color="green"&gt;//  for (int i = 0; i &amp;lt; range.Height; i++)
&lt;/font&gt;          &lt;font color="green"&gt;//  {
&lt;/font&gt;          &lt;font color="green"&gt;//    if (rowData is object[])
&lt;/font&gt;          &lt;font color="green"&gt;//    {
&lt;/font&gt;          &lt;font color="green"&gt;//      object[] columnData = rowData[i] as object[];
&lt;/font&gt;          &lt;font color="green"&gt;//      if (columnData[0] == null)
&lt;/font&gt;          &lt;font color="green"&gt;//      {
&lt;/font&gt;          &lt;font color="green"&gt;//        // No more translations
&lt;/font&gt;          &lt;font color="green"&gt;//        doneTranslations = true;
&lt;/font&gt;          &lt;font color="green"&gt;//        break;
&lt;/font&gt;          &lt;font color="green"&gt;//      }
&lt;/font&gt;          &lt;font color="green"&gt;//      string[] translationRange = Convert.ToString(columnData[0]).Split('!');
&lt;/font&gt;          &lt;font color="green"&gt;//      es.SetCellA1(sessionId, translationRange[0], translationRange[1],
&lt;/font&gt;          &lt;font color="green"&gt;//        Convert.ToString(columnData[1]), out status);
&lt;/font&gt;          &lt;font color="green"&gt;//    }
&lt;/font&gt;          &lt;font color="green"&gt;//  }
&lt;/font&gt;          &lt;font color="green"&gt;//  range.Row += range.Height;
&lt;/font&gt;          &lt;font color="green"&gt;//}
&lt;/font&gt;          &lt;br&gt;          &lt;font color="#008000"&gt;// Do we calculations that we need to refresh?&lt;/font&gt;&lt;br&gt;          es.CalculateWorkbook(sessionId, &lt;font color="#008080"&gt;CalculateType&lt;/font&gt;.CalculateFull, &lt;font color="blue"&gt;out&lt;/font&gt; status);
          &lt;font color="#0000ff"&gt;byte&lt;/font&gt;[] wb = es.GetWorkbook(sessionId, &lt;font color="#008080"&gt;WorkbookType&lt;/font&gt;.FullWorkbook, &lt;font color="blue"&gt;out&lt;/font&gt; status);
          es.CloseWorkbook(sessionId, &lt;font color="blue"&gt;out&lt;/font&gt; status);

          &lt;font color="green"&gt;// Let's write our cache file to the disk:
&lt;/font&gt;          &lt;font color="green"&gt;// (you need to have write rights for that location!)
&lt;/font&gt;          &lt;font color="#008080"&gt;File&lt;/font&gt;.WriteAllBytes(xlFile, wb);
        }
      }

      &lt;font color="green"&gt;// TODO: set all necessary parameters to EWA:
&lt;/font&gt;      ewa.ShowWorkbookParameters = &lt;font color="blue"&gt;false&lt;/font&gt;;
      ewa.WorkbookUri = &lt;font color="#008080"&gt;Uri&lt;/font&gt;.UriSchemeFile + &lt;font color="#008080"&gt;Uri&lt;/font&gt;.SchemeDelimiter + xlFile;
      ewa.ToolbarStyle = &lt;font color="#008080"&gt;ToolbarVisibilityStyle&lt;/font&gt;.None;
      ewa.ChromeType = &lt;font color="#008080"&gt;PartChromeType&lt;/font&gt;.None;

      &lt;font color="green"&gt;// TODO: you can also get settings from various places:
&lt;/font&gt;      &lt;font color="blue"&gt;if&lt;/font&gt; (&lt;font color="blue"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"NamedItem"&lt;/font&gt;&lt;/font&gt;]) == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        ewa.VisibleItem = &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"NamedItem"&lt;/font&gt;&lt;/font&gt;].ToString();
      }
      &lt;font color="blue"&gt;if&lt;/font&gt; (&lt;font color="blue"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Rows"&lt;/font&gt;&lt;/font&gt;]) == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        ewa.RowsToDisplay = &lt;font color="#008080"&gt;Convert&lt;/font&gt;.ToInt32(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Rows"&lt;/font&gt;&lt;/font&gt;]);
      }
      &lt;font color="blue"&gt;if&lt;/font&gt; (&lt;font color="blue"&gt;string&lt;/font&gt;.IsNullOrEmpty(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Columns"&lt;/font&gt;&lt;/font&gt;]) == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        ewa.ColumnsToDisplay = &lt;font color="#008080"&gt;Convert&lt;/font&gt;.ToInt32(&lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request[&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Columns"&lt;/font&gt;&lt;/font&gt;]);
      }
    }

    &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="blue"&gt;string&lt;/font&gt; GetSnapshotFile()
    {
      &lt;font color="#0000ff"&gt;byte&lt;/font&gt;[] wb;
      &lt;font color="blue"&gt;string&lt;/font&gt; snapshotCacheFile = xlFile + &lt;font color="#aa2000"&gt;".snapshot.xlsx"&lt;/font&gt;;
      &lt;font color="blue"&gt;if&lt;/font&gt; (&lt;font color="#008080"&gt;File&lt;/font&gt;.Exists(snapshotCacheFile) == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        &lt;font color="green"&gt;&lt;font color="green"&gt;// No cache file yet.. so let's create it:
&lt;/font&gt;&lt;/font&gt;        &lt;font color="blue"&gt;using&lt;/font&gt; (&lt;font color="#008080"&gt;ExcelService&lt;/font&gt; es = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;ExcelService&lt;/font&gt;())
        {
          &lt;font color="#008080"&gt;Status&lt;/font&gt;[] status;
          &lt;font color="blue"&gt;string&lt;/font&gt; sessionId = es.OpenWorkbook(xlFile, culture, culture, &lt;font color="blue"&gt;out&lt;/font&gt; status);
          &lt;font color="green"&gt;// Note! If we take the 'normal' excel file then we return formulas as well
&lt;/font&gt;          &lt;font color="green"&gt;// =&amp;gt; we really want to use the snapshot file!
&lt;/font&gt;          wb = es.GetWorkbook(sessionId, &lt;font color="#008080"&gt;WorkbookType&lt;/font&gt;.PublishedItemsSnapshot, &lt;font color="blue"&gt;out&lt;/font&gt; status);
          es.CloseWorkbook(sessionId, &lt;font color="blue"&gt;out&lt;/font&gt; status);
        }

        &lt;font color="#008080"&gt;File&lt;/font&gt;.WriteAllBytes(snapshotCacheFile, wb);
      }

      &lt;font color="blue"&gt;return&lt;/font&gt; snapshotCacheFile;
    }

    &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="blue"&gt;string&lt;/font&gt; BuildExportScript(&lt;font color="blue"&gt;string&lt;/font&gt; exportFormat, &lt;font color="blue"&gt;string&lt;/font&gt; file)
    {
      &lt;font color="blue"&gt;string&lt;/font&gt; url = &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Request.Url.ToString();
      &lt;font color="blue"&gt;if&lt;/font&gt; (url.IndexOf(&lt;font color="#800000"&gt;'?'&lt;/font&gt;) == -1)
      {
        url += &lt;font color="#aa2000"&gt;"?"&lt;/font&gt;;
      }
      &lt;font color="blue"&gt;&lt;font color="blue"&gt;else&lt;/font&gt;&lt;/font&gt;
      {
        url += &lt;font color="#aa2000"&gt;"&amp;amp;"&lt;/font&gt;;
      }
      url += &lt;font color="#aa2000"&gt;"ExportFormat="&lt;/font&gt; + exportFormat + &lt;font color="#aa2000"&gt;"&amp;amp;File="&lt;/font&gt; + file;
      &lt;font color="blue"&gt;return&lt;/font&gt; &lt;font color="#aa2000"&gt;"window.frames['MyEWA'].location='"&lt;/font&gt; + url + &lt;font color="#aa2000"&gt;"'; return false;"&lt;/font&gt;;
    }

    &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="blue"&gt;void&lt;/font&gt; ExportSnapshotAsExcel()
    {
      &lt;font color="#0000ff"&gt;byte&lt;/font&gt;[] fileData = &lt;font color="#008080"&gt;File&lt;/font&gt;.ReadAllBytes(&lt;font color="blue"&gt;this&lt;/font&gt;.GetSnapshotFile());
      &lt;font color="green"&gt;&lt;font color="green"&gt;// TODO: set meaningful name for the file (end user sees it File Download dialog)
&lt;/font&gt;&lt;/font&gt;      &lt;font color="blue"&gt;string&lt;/font&gt; filename = &lt;font color="#aa2000"&gt;"ExcelData.xlsx"&lt;/font&gt;;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.ClearHeaders();
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.ClearContent();
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.AppendHeader(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Content-Disposition"&lt;/font&gt;&lt;/font&gt;, 
        &lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"attachment;filename="&lt;/font&gt;&lt;/font&gt; + filename);
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.AddHeader(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"LAST-MODIFIED"&lt;/font&gt;&lt;/font&gt;, DateTime.Now.ToString(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"r"&lt;/font&gt;&lt;/font&gt;));
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.ContentType = 
        &lt;font color="#aa2000"&gt;"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"&lt;/font&gt;;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.OutputStream.Write(fileData, 0, fileData.Length);
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.OutputStream.Flush();
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.End();
    }

    &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="blue"&gt;string&lt;/font&gt; GetSnapshotFileCSV()
    {
      &lt;font color="#409090"&gt;StringBuilder&lt;/font&gt; sb = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#409090"&gt;StringBuilder&lt;/font&gt;(2048);
      &lt;font color="blue"&gt;string&lt;/font&gt; snapshotCacheFile = xlFile + &lt;font color="#aa2000"&gt;".snapshot.csv"&lt;/font&gt;;
      &lt;font color="blue"&gt;if&lt;/font&gt; (&lt;font color="#008080"&gt;File&lt;/font&gt;.Exists(snapshotCacheFile) == &lt;font color="blue"&gt;false&lt;/font&gt;)
      {
        &lt;font color="green"&gt;&lt;font color="green"&gt;// No cache file yet.. so let's create it:
&lt;/font&gt;&lt;/font&gt;        &lt;font color="blue"&gt;using&lt;/font&gt; (&lt;font color="#008080"&gt;ExcelService&lt;/font&gt; es = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;ExcelService&lt;/font&gt;())
        {
          &lt;font color="#008080"&gt;Status&lt;/font&gt;[] status;
          &lt;font color="blue"&gt;string&lt;/font&gt; sessionId = es.OpenWorkbook
            (&lt;font color="blue"&gt;this&lt;/font&gt;.GetSnapshotFile(), culture, culture, &lt;font color="blue"&gt;out&lt;/font&gt; status);
          RangeCoordinates range = &lt;font color="blue"&gt;new&lt;/font&gt; RangeCoordinates();
          range.Column = 0;
          range.Row = 0;
          &lt;font color="green"&gt;// TODO: get real range according to the data (not fixed :-)
&lt;/font&gt;          &lt;font color="green"&gt;// You could store the value when you fill the Excel with data...
&lt;/font&gt;          range.Width = 5;
          range.Height = 300;

          &lt;font color="blue"&gt;object&lt;/font&gt;[] data = es.GetRange(sessionId, &lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Display"&lt;/font&gt;&lt;/font&gt;, range, &lt;font color="blue"&gt;false&lt;/font&gt;, &lt;font color="blue"&gt;out&lt;/font&gt; status);
          &lt;font color="blue"&gt;foreach&lt;/font&gt; (&lt;font color="blue"&gt;object&lt;/font&gt; row in data)
          {
            &lt;font color="blue"&gt;if&lt;/font&gt; (row &lt;font color="blue"&gt;is&lt;/font&gt; &lt;font color="blue"&gt;object&lt;/font&gt;[])
            {
              &lt;font color="blue"&gt;object&lt;/font&gt;[] columns = row as &lt;font color="blue"&gt;object&lt;/font&gt;[];
              &lt;font color="blue"&gt;foreach&lt;/font&gt; (&lt;font color="blue"&gt;object&lt;/font&gt; columnData in columns)
              {
                &lt;font color="blue"&gt;if&lt;/font&gt; (columnData != &lt;font color="blue"&gt;null&lt;/font&gt;)
                {
                  sb.Append(columnData);
                }
                sb.Append(&lt;font color="#aa2000"&gt;";"&lt;/font&gt;);
              }
              sb.Append(&lt;font color="#409090"&gt;Environment&lt;/font&gt;.NewLine);
            }
          }

          es.CloseWorkbook(sessionId, &lt;font color="blue"&gt;out&lt;/font&gt; status);
        }

        &lt;font color="#008080"&gt;File&lt;/font&gt;.WriteAllBytes(snapshotCacheFile, 
          &lt;font color="#008080"&gt;Encoding&lt;/font&gt;.Convert(&lt;font color="#008080"&gt;Encoding&lt;/font&gt;.UTF7, 
          &lt;font color="#008080"&gt;Encoding&lt;/font&gt;.GetEncoding(&lt;font color="#aa2000"&gt;"windows-1250"&lt;/font&gt;), 
          &lt;font color="#008080"&gt;Encoding&lt;/font&gt;.UTF7.GetBytes(sb.ToString())));
      }

      &lt;font color="blue"&gt;return&lt;/font&gt; snapshotCacheFile;
    }

    &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="blue"&gt;void&lt;/font&gt; ExportSnapshotAsCSV()
    {
      &lt;font color="#0000ff"&gt;byte&lt;/font&gt;[] fileData = &lt;font color="#008080"&gt;File&lt;/font&gt;.ReadAllBytes(&lt;font color="blue"&gt;this&lt;/font&gt;.GetSnapshotFileCSV());

      &lt;font color="green"&gt;&lt;font color="green"&gt;// TODO: set meaningful name for the file (end user sees it)
&lt;/font&gt;&lt;/font&gt;      &lt;font color="blue"&gt;string&lt;/font&gt; filename = &lt;font color="#aa2000"&gt;"CSVData.csv"&lt;/font&gt;;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.Clear();
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.AppendHeader(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"Content-Disposition"&lt;/font&gt;&lt;/font&gt;, &lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"attachment;filename="&lt;/font&gt;&lt;/font&gt; + filename);
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.AddHeader(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"LAST-MODIFIED"&lt;/font&gt;&lt;/font&gt;, DateTime.Now.ToString(&lt;font color="#aa2000"&gt;&lt;font color="#aa2000"&gt;"r"&lt;/font&gt;&lt;/font&gt;));
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.ContentType = &lt;font color="#aa2000"&gt;"text/plain"&lt;/font&gt;;
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.OutputStream.Write(fileData, 0, fileData.Length);
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.Flush();
      &lt;font color="blue"&gt;this&lt;/font&gt;.Page.Response.End();
    }

    &lt;font color="blue"&gt;protected&lt;/font&gt; &lt;font color="blue"&gt;override&lt;/font&gt; &lt;font color="blue"&gt;void&lt;/font&gt; Render(&lt;font color="#409090"&gt;HtmlTextWriter&lt;/font&gt; writer)
    {
      &lt;font color="blue"&gt;this&lt;/font&gt;.RenderChildren(writer);

      &lt;font color="green"&gt;// Let's add our export iframe:
&lt;/font&gt;      writer.Write(&lt;font color="#aa2000"&gt;"&lt;/font&gt;&lt;font color="#800000"&gt;&amp;lt;iframe name=\"MyEWA\" src=\"about:blank\" width=\"1\" height=\"1\" /&amp;gt;"&lt;/font&gt;);
    }
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;I'm not going to explain code since most of that is quite easily understandable... but if you have questions then post comment to this entry and I'll get back to you.&lt;/p&gt;
&lt;p&gt;You can probably see that I have added a lot of "&lt;font color="#008000"&gt;// TODO:&lt;/font&gt;"-markers to identify places you most likely will be doing some modifications if you plan to use my code. I also left some code blocks that I have tried and noticed that it doesn't work as you would expect. Good example is that you cannot change the caption / labels of the pivottable. You CAN do that in Excel but you cannot do that using Excel Services API. So in other words... this doesn't work:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;es.SetCellA1(sessionId, "Display", "A5", "My Pivottable caption", out status);&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That is the reason why I have actually hidden that row. User sees still caption but it's just normal text that is formatted so that it looks like caption :-) But if I unhide &lt;em&gt;A5&lt;/em&gt; it would look like this:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:0d3f2bc8-0f86-489a-87a0-b290295a0e6d" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5931138/original.aspx" alt="" style="width:377px; height:83px;" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But again... that caption isn't visible if you export Excel (row 5 is empty but user needs to &lt;em&gt;Unhide&lt;/em&gt; that row in order to see it):&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:283227ab-a1b7-4a9b-af3a-e47b41b44fd8" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5931207/original.aspx" alt="" style="width:379px; height:79px;" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Another Excel tip that you need is Pivottable filters. Because if you don't set any filter you would get "(blank)" rows into table. That can be filtered away with &lt;em&gt;label filters&lt;/em&gt;:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:b90c3b95-5eb8-433b-82b6-8e82d24c1833" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5931285/original.aspx" alt="" style="width:482px; height:279px;" /&gt;&lt;/div&gt;
&lt;p&gt;Set "&lt;em&gt;Does Not Equal...&lt;/em&gt;" -filter to be empty:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:766dd9c8-8eb3-43b9-9ec8-a2b4e3047b0b" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5931297/original.aspx" alt="" style="width:405px; height:151px;" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And after that you don't get those "(blank)" rows in your pivottable.&lt;/p&gt;
&lt;p&gt;If you're interestested that how did my solution look like inside VS:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:2553f03b-e295-4517-8d22-ab1e9f5dc85d" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5931506/original.aspx" alt="" style="width:247px; height:132px;" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So I had resource files for &lt;em&gt;default&lt;/em&gt; language and &lt;em&gt;fi-FI&lt;/em&gt;. Since I used SharePoint &lt;em&gt;Web Part&lt;/em&gt; template (I like some much the F5 integration :-) I needed manually copy the &lt;em&gt;fi-FI&lt;/em&gt; folder under my projects &lt;em&gt;Debug&lt;/em&gt; folder under the web applications bin directory: &lt;em&gt;C:\Inetpub\wwwroot\wss\VirtualDirectories\1000\bin&lt;/em&gt;. I just wanted to mention this if you have issues with your resource files :-)&lt;/p&gt;
&lt;h3&gt;Performance?&lt;/h3&gt;
&lt;p&gt;I ended up doing a lot of static Excel files... so I think that it should be fast since now there isn't any database queries happening (not verified). BUT at least I managed to demonstrate that you could create static files so that if everything goes fine you should benefit from memory of your app servers. And if your data changes rarely you can easily create script that forces all the cache files to be created (just loops all the necessary HTTP requests). This would be trivial to implement. Here is one example call:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;http://demo1:1000/fi-FI/Sivut/MunEWA.aspx?ExportFormat=csv&amp;amp;File=MyEWA-fi-FI-Mountain.xlsx&amp;amp;Language=en-US&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can modify &lt;em&gt;ExportFormat&lt;/em&gt; and &lt;em&gt;File&lt;/em&gt; and &lt;em&gt;Language&lt;/em&gt; in order to get file that you want.&lt;/p&gt;
&lt;p&gt;And if you think this solution more deeply... actually you don't need even database at the production environment since you create static copies of Excels in another environment (i.e. publishing environment) :-) That would be another way to look at this solution... just distribute static Excel files between environments.&lt;/p&gt;
&lt;h3&gt;What's other possibilies I have?&lt;/h3&gt;
&lt;p&gt;You probably at least two more options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;OLAP + CUBE* -functions inside Excel 
&lt;ul&gt;
&lt;li&gt;You need to create ODC for the OLAP connection 
&lt;ul&gt;
&lt;li&gt;Store this in &lt;em&gt;Data Connection Library&lt;/em&gt; in SharePoint 
&lt;li&gt;You need to configure Single Single-On Service (SSO) to pass the credentials&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;You would have a better way to handle data 
&lt;li&gt;Downside: 
&lt;ul&gt;
&lt;li&gt;If you change filter =&amp;gt; new database request! 
&lt;li&gt;You will still have same issues with pivottable that with "old relational" pivottable&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;UDF (User Defined Function) 
&lt;ul&gt;
&lt;li&gt;Create still all the data retrieval logic with .NET 
&lt;ul&gt;
&lt;li&gt;In Excel you would have something like this "=MyRetrieveData(Parameters!B2:Parameters:!B6)"&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;Downside: 
&lt;ul&gt;
&lt;li&gt;No preview :-( 
&lt;li&gt;Database requests&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;&lt;strong&gt;NOTE: &lt;/strong&gt;You can use this in your Excels even if you dynamically create the static instances! 
&lt;ul&gt;
&lt;li&gt;It could be probably good idea to use this for complex logic&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I haven't validated those as detailed as I have this "static Excel instances" approach so I might be missing something important about the other approaches :-)&lt;/p&gt;
&lt;h3&gt;More information about Excel Services and Excel&lt;/h3&gt;
&lt;p&gt;As always... internet is full of stuff around Excel Services but you might want to check out at least these:&lt;/p&gt;
&lt;p&gt;&lt;a title="http://technet2.microsoft.com/Office/en-us/library/eea3ace8-0863-429a-b1e8-041254ed2fc41033.mspx?mfr=true" href="http://technet2.microsoft.com/Office/en-us/library/eea3ace8-0863-429a-b1e8-041254ed2fc41033.mspx?mfr=true"&gt;http://technet2.microsoft.com/Office/en-us/library/eea3ace8-0863-429a-b1e8-041254ed2fc41033.mspx?mfr=true&lt;/a&gt; -- White papers: Excel Services step-by-step guides&lt;/p&gt;
&lt;p&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/bb267252.aspx#Office2007ExcelServicesUnlimited_SharePointLists" href="http://msdn2.microsoft.com/en-us/library/bb267252.aspx#Office2007ExcelServicesUnlimited_SharePointLists"&gt;http://msdn2.microsoft.com/en-us/library/bb267252.aspx#Office2007ExcelServicesUnlimited_SharePointLists&lt;/a&gt; -- Extending the Excel Services Programmability Framework&lt;/p&gt;
&lt;p&gt;&lt;a title="http://www.microsoft.com/downloads/details.aspx?FamilyId=2D779CD5-EEB2-43E9-BDFA-641ED89EDB6C&amp;amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=2D779CD5-EEB2-43E9-BDFA-641ED89EDB6C&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=2D779CD5-EEB2-43E9-BDFA-641ED89EDB6C&amp;amp;displaylang=en&lt;/a&gt; -- Excel 2007 Document: Designing SQL Server 2005 Analysis Services Cubes for Excel 2007 PivotTables&lt;/p&gt;
&lt;p&gt;&lt;a title="http://blogs.msdn.com/cumgranosalis/" href="http://blogs.msdn.com/cumgranosalis/"&gt;http://blogs.msdn.com/cumgranosalis/&lt;/a&gt; -- Cum Grano Salis&lt;/p&gt;
&lt;p&gt;&lt;a title="http://blogs.msdn.com/luisbeonservices/" href="http://blogs.msdn.com/luisbeonservices/"&gt;http://blogs.msdn.com/luisbeonservices/&lt;/a&gt; -- LuisBE on Services&lt;/p&gt;
&lt;p&gt;&lt;a title="http://blogs.msdn.com/excel/" href="http://blogs.msdn.com/excel/"&gt;http://blogs.msdn.com/excel/&lt;/a&gt; -- The team blog for Microsoft Excel and Excel Services&lt;/p&gt;
&lt;p&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/bb758869.aspx" href="http://msdn2.microsoft.com/en-us/library/bb758869.aspx"&gt;http://msdn2.microsoft.com/en-us/library/bb758869.aspx&lt;/a&gt; -- Chapter 1: An Introduction to Excel Services&lt;/p&gt;
&lt;p&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/bb758868.aspx" href="http://msdn2.microsoft.com/en-us/library/bb758868.aspx"&gt;http://msdn2.microsoft.com/en-us/library/bb758868.aspx&lt;/a&gt; -- Chapter 3: Excel Web Access&lt;/p&gt;
&lt;h3&gt;Final words&lt;/h3&gt;
&lt;p&gt;Well that ended up being looong post :-) I'll probably still work on this subject so I might get back with follow-ups. I'll probably do some performance tests so that I'll get some indications that how well this does work.&lt;/p&gt;
&lt;p&gt;This subject is actually quite complex. I don't consider this case as solved... I just consider this as good kickstart :-) There are still many open questions like: "&lt;em&gt;What's the best place to do translations?&lt;/em&gt;" (and many more). Well I don't have answer to that since I think it's not that black and white :-) You may see that some are easy to translate in DB but same are too hard (or database model doesn't support it) and then you need to do that somewhere else.&lt;/p&gt;
&lt;p&gt;If you plan to use this code you first need to generalize it since my solution is quite fixed to one certain Excel file. But I think that is actually quite easy task and I'll let you work on that.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5939871" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Excel+Services/default.aspx">Excel Services</category></item><item><title>Adding own custom web service to SharePoint</title><link>http://blogs.msdn.com/jannemattila/archive/2007/09/26/adding-own-custom-web-service-to-sharepoint.aspx</link><pubDate>Wed, 26 Sep 2007 22:10:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5149054</guid><dc:creator>jannemattila</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/5149054.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=5149054</wfw:commentRss><description>&lt;p&gt;I posted awhile back about &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/01/21/infopath-and-web-service-data-connection.aspx" target="_blank"&gt;InfoPath and Web Service data connection&lt;/a&gt; and I got &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/01/21/infopath-and-web-service-data-connection.aspx#5123929" target="_blank"&gt;question&lt;/a&gt; about using own web services in SharePoint (or at least I interpreted it that way :-). I tried to describe idea to have own custom "proxy" web service that would do all the necessary stuff inside SharePoint so that you could use local API and not the web service API. So if you know about application pages then you know what I'm talking about. Same things apply to web services too. But as always... I'm not good at telling stuff so let's jump to the code :-)&lt;/p&gt; &lt;p&gt;I just quickly created &lt;em&gt;Microsoft.MCS.WebService.ExampleWebService.asmx &lt;/em&gt;and added it to the layouts folder (=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS). This time I skipped features/solutions and did my example the easy way (as always :-).&lt;/p&gt; &lt;p&gt;Here is the content of the &lt;em&gt;.asmx&lt;/em&gt; file:&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&amp;lt;%@ &lt;font color="#800000"&gt;WebService&lt;/font&gt; &lt;font color="#ff0000"&gt;Class&lt;/font&gt;&lt;font color="#0000ff"&gt;="Microsoft.MCS.WebService.ExampleWebService,
Microsoft.MCS.WebService,Version=1.0.0.0,Culture=neutral,PublicKeyToken=a030a6768fa75cfc"&lt;/font&gt; %&amp;gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;And code behind is in here (I signed it and put it into GAC):&lt;/p&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="blue"&gt;using&lt;/font&gt; System;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Web.Services;
&lt;font color="blue"&gt;using&lt;/font&gt; Microsoft.SharePoint;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Security.Principal;

&lt;font color="blue"&gt;namespace&lt;/font&gt; Microsoft.MCS.WebService
{
  &lt;font color="blue"&gt;public&lt;/font&gt; &lt;font color="blue"&gt;class&lt;/font&gt; &lt;font color="#008080"&gt;ExampleWebService&lt;/font&gt; : System.Web.Services.&lt;font color="#008080"&gt;WebService&lt;/font&gt;
  {
    [&lt;font color="#008080"&gt;WebMethod&lt;/font&gt;]
    &lt;font color="blue"&gt;public&lt;/font&gt; &lt;font color="blue"&gt;string&lt;/font&gt; WhoAmI()
    {
      &lt;font color="blue"&gt;return&lt;/font&gt; &lt;font color="#008080"&gt;WindowsIdentity&lt;/font&gt;.GetCurrent().Name +
          &lt;font color="#aa2000"&gt;" &amp;lt;-&amp;gt;"&lt;/font&gt; + &lt;font color="#008080"&gt;SPContext&lt;/font&gt;.Current.Web.CurrentUser.LoginName;
    }
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Code is pretty simple since it just returns string that contains current users &lt;em&gt;WindowsIdentity&lt;/em&gt; name and &lt;em&gt;LoginName&lt;/em&gt; using SharePoint API. &lt;/p&gt;
&lt;p&gt;If you run this stuff directly from SharePoint using browser you'll get something like this:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:a7175267-e338-4a5b-a65c-555e29752863" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5148598/original.aspx" alt="" style="width:693px; height:343px;" /&gt;&lt;/div&gt;
&lt;p&gt;And now you can use this stuff from InfoPath as well:&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:b3d64348-db32-4152-8656-dca446d1b9e2" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5148611/original.aspx" alt="" style="width:662px; height:203px;" /&gt;&lt;/div&gt;&lt;br&gt;So if you want to have weird SharePoint functionality (like enumerating lists) in your InfoPath forms you could use your own "proxy" web service to make it happen. This example was just skeleton that shows that this kind of stuff can be done but the exact implementation is left to you. I hope that I answered one of the questions that have been asked in my blog :-) &lt;br&gt;&lt;br&gt;And if you try to update stuff in your code you'll most likely end up with &lt;em&gt;SPException&lt;/em&gt; saying that "&lt;em&gt;The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.&lt;/em&gt;"... but don't worry because that's the way it works :-) You can turn off the security validation check temporary with &lt;em&gt;AllowUnsafeUpdates = true&lt;/em&gt;. I'll leave rest of that stuff for you...&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5149054" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category></item><item><title>MOSS: Backup and restore and missing Timer job definitions</title><link>http://blogs.msdn.com/jannemattila/archive/2007/08/31/moss-backup-and-restore-and-missing-timer-job-definitions.aspx</link><pubDate>Fri, 31 Aug 2007 13:44:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4667204</guid><dc:creator>jannemattila</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/4667204.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=4667204</wfw:commentRss><description>&lt;p&gt;If you have your SharePoint application running on Server1 and you decide to move it to Server2 with backup&amp;nbsp;and restore... you'll (may) end up having application at the Server2 that doesn't have all the necessary timer job definitions. There is however way to get those timer job definitions back but it's not the most elegant way :-)&lt;/p&gt; &lt;p&gt;So you have restored your system&amp;nbsp;(for example&amp;nbsp;"&lt;em&gt;stsadm -o restore -url http://demo1:1000/ -filename Backup.dat&lt;/em&gt;")&amp;nbsp;to Server2 and you'll go to Central Administration to see all the timer job definitions of your application:&lt;/p&gt; &lt;p&gt; &lt;div class="wlWriterSmartContent" id="6960CE03-38FC-44df-87D4-FA4540212B06:c2e8e1f0-2636-4209-8ec2-e091a05f9c06" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/4665411/original.aspx" alt="" style="width:481px; height:408px;"&gt;&lt;/div&gt;&lt;/p&gt; &lt;p&gt;It looks like everything is fine... but if you compare this list to another application:&lt;/p&gt; &lt;p&gt; &lt;div class="wlWriterSmartContent" id="6960CE03-38FC-44df-87D4-FA4540212B06:4c81f220-5233-4a46-943b-0577613f0c42" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/4665432/original.aspx" alt="" style="width:484px; height:503px;"&gt;&lt;/div&gt;&lt;/p&gt; &lt;p&gt;So quite easily you can spot that this list is a lot longer for the another application (14 vs. 19)! If you compare them by each entry then you'll notice that your application is missing: &lt;/p&gt; &lt;p&gt;...&lt;br&gt;&lt;em&gt;Scheduled Approval&amp;nbsp; SharePoint - 80&amp;nbsp; Minutes&amp;nbsp; &lt;br&gt;Scheduled Page Review&amp;nbsp; SharePoint - 80&amp;nbsp; Daily&amp;nbsp; &lt;br&gt;Scheduled Unpublish&amp;nbsp; SharePoint - 80&amp;nbsp; Minutes&amp;nbsp; &lt;br&gt;&lt;/em&gt;...&lt;br&gt;&lt;em&gt;Variations Propagate Page Job Definition&amp;nbsp; SharePoint - 80&amp;nbsp; Minutes&amp;nbsp; &lt;br&gt;Variations Propagate Site Job Definition&amp;nbsp; SharePoint - 80&amp;nbsp; Minutes&amp;nbsp; &lt;br&gt;&lt;/em&gt;... &lt;p&gt;That means that if you want to use &lt;em&gt;Scheduled publishing&lt;/em&gt; you won't be able to do so :-( And you would have problems with &lt;em&gt;Variations &lt;/em&gt;too. &lt;p&gt;But let's try and see what actually happens &lt;em&gt;Scheduled publishing&lt;/em&gt;. I created page that should be published at 1:00 PM: &lt;p&gt; &lt;div class="wlWriterSmartContent" id="6960CE03-38FC-44df-87D4-FA4540212B06:c2962fa9-fa9e-4512-b5d5-5b7f7fa54659" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/4665540/original.aspx" alt="" style="width:840px; height:69px;"&gt;&lt;/div&gt;&lt;/p&gt; &lt;p&gt;After a while error message comes to the toolbar (it comes few minutes after it should be published):&lt;/p&gt; &lt;p&gt; &lt;div class="wlWriterSmartContent" id="6960CE03-38FC-44df-87D4-FA4540212B06:62483b1f-e856-4e81-bffd-ccf6bc6e4d7f" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/4665575/original.aspx" alt="" style="width:837px; height:91px;"&gt;&lt;/div&gt;&lt;/p&gt; &lt;p&gt;So "&lt;em&gt;An error occurred trying to publish this page on the set schedule. Republish the page with a new date or view the log if the problem continues.&lt;/em&gt;" will be you destiny... and page won't be published. But this was expected since we're missing timer job for that. &lt;/p&gt; &lt;p&gt;In order to fix this you need to actually create site collection to your application that will create those timer job definitions (ex. &lt;em&gt;Publishing Portal &lt;/em&gt;or &lt;em&gt;Collaboration Portal&lt;/em&gt;). &lt;strong&gt;NOTE: &lt;/strong&gt;You really need to use one of those templates that will create those timer jobs. If you use ex. &lt;em&gt;Blank Site&lt;/em&gt; you won't have those timer job definitions that you're looking for. After you have created the new site collection you can go and verify that it has created those 5 timer jobs. After this you can go and delete the newly created site collection and restore your own system back to the application.&lt;/p&gt; &lt;p&gt;Reason for this seems to&amp;nbsp;be that restore just creates those 14 timer job definitions and doens't restore the ones that are build on top of the base WSS. So in order to get those back you need to do this small trick that I have just described in this post.&lt;/p&gt; &lt;p&gt;To summarize... if you want to transfer your system you need to follow couple of extra steps:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Create new web application&lt;/li&gt; &lt;li&gt;Create new site collection to your application&lt;/li&gt; &lt;ul&gt; &lt;li&gt;Use &lt;em&gt;Publishing Portal &lt;/em&gt;or &lt;em&gt;Collaboration Portal &lt;/em&gt;templates!&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Verify that you have all the necessary timer jobs&lt;/li&gt; &lt;li&gt;Delete your newly created site collection&lt;/li&gt; &lt;li&gt;Restore your own system&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;I hope I made someones life a bit easier with this post. I don't think that this is the first thing that comes to your mind when you're&amp;nbsp;WCM page gives you error message when it should be published :-)&amp;nbsp;&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4667204" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category></item><item><title>Failed to determine definition for Feature...</title><link>http://blogs.msdn.com/jannemattila/archive/2007/08/27/failed-to-determine-definition-for-feature.aspx</link><pubDate>Mon, 27 Aug 2007 16:04:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4592170</guid><dc:creator>jannemattila</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/4592170.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=4592170</wfw:commentRss><description>&lt;p&gt;I was working on SharePoint case and found myself staring at the logs... again :-)&lt;/p&gt; &lt;p&gt;I found 11 lines with "&lt;em&gt;Failed to determine definition for Feature with ID&lt;/em&gt;..." and it was repeating quite often. And that error is something new for me... And if you have stared SharePoint logs for an year that's really amazing! Exact error messages were like this:&lt;/p&gt; &lt;p&gt;...&lt;br&gt;Failed to determine definition for Feature with ID '065c78be-5231-477e-a972-14177cc5b3c7'.&amp;nbsp; Skipping this feature for element querying consideration.&lt;br&gt;Failed to determine definition for Feature with ID '0806d127-06e6-447a-980e-2e90b03101b8'.&amp;nbsp; Skipping this feature for element querying consideration.&lt;br&gt;Failed to determine definition for Feature with ID '2510d73f-7109-4ccc-8a1c-314894deeb3a'.&amp;nbsp; Skipping this feature for element querying consideration.&lt;br&gt;Failed to determine definition for Feature with ID '00bfea71-dbd7-4f72-b8cb-da7ac0440130'.&amp;nbsp; Skipping this feature for element querying consideration.&lt;br&gt;...  &lt;p&gt;So I searched (with Vesa Juvonen) those guids from &lt;em&gt;12\TEMPLATE\Features&lt;/em&gt;-folder and found out that those features were actually Enterprise Edition features (like Excel Services). MOSS "couldn't find" those features even if they were OOB features. The reason for this was actually quite understandable... since there was a site collection that has been moved from MOSS Enterprise to Standard. And in Standard you don't have those Enterpise Edition features available even you have those activated in you site collection. The lesson of this exercise was... don't mix and match editions :-)&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4592170" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category></item><item><title>How to install Windows SharePoint Services 3.0 Tools to XP or Vista</title><link>http://blogs.msdn.com/jannemattila/archive/2007/08/16/how-to-install-windows-sharepoint-services-3-0-tools-to-xp-or-vista.aspx</link><pubDate>Thu, 16 Aug 2007 06:42:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4409644</guid><dc:creator>jannemattila</dc:creator><slash:comments>82</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/4409644.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=4409644</wfw:commentRss><description>&lt;p&gt;I got email from Philip Edney with a hint that how you can install &lt;em&gt;&lt;a title="VSeWSS download" href="http://www.microsoft.com/downloads/details.aspx?familyid=19f21e5e-b715-4f0c-b959-8c6dcbdc1057&amp;amp;displaylang=en" target="_blank"&gt;Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions (VSeWSS)&lt;/a&gt;&amp;nbsp; &lt;/em&gt;for none-Windows 2003 server OS. Of course since that's &lt;strong&gt;not supported &lt;/strong&gt;you'll have to do small registry hack (but that's what developers do&amp;nbsp;:-):&lt;/p&gt; &lt;p&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0] &lt;br&gt;"Sharepoint"="Installed"  &lt;p&gt;I just tested it with Windows Vista and it works! Before the hack it gives me "&lt;em&gt;This product can be installed if Windows SharePoint Services 3.0 has been installed first.&lt;/em&gt;" and after the hack it went fine. I think there're a lot of people who would like to&amp;nbsp;try/use this&amp;nbsp;option even if they fall for unsupported mode.  &lt;p&gt;But thanks to Phil to let me know about that possibility! &lt;strong&gt;Update:&lt;/strong&gt; Phil mentioned that he actually got the information from Raju Sakthivel so the credits chain just goes on and on :-)&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4409644" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Application+Development/default.aspx">Application Development</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx">Microsoft Office SharePoint Server 2007</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category></item></channel></rss>