jasonontheweb-blog
jasonontheweb-blog
Jason On The Web
17 posts
I like the internet, SharePoint, jQuery and ASP.net MVC. I still have a lot to learn.
Don't wanna be here? Send us removal request.
jasonontheweb-blog · 14 years ago
Text
jQuery Rocks: align the top of the last divs in a set of containers
var max = 0; $("div.top-nav-footer").each(function () { var elTop = $(this).offset().top; max = max > elTop ? max : elTop; }).each(function () { var offset = $(this).offset(); $(this).offset({ "top": (max + 30) }); });
5 notes · View notes
jasonontheweb-blog · 14 years ago
Text
Code changes not taking effect when developing features
Wasted a chunk of time because I kept getting a "method not found SomeCLass..ctor()" error.  Regardless of the error the fact was that the constructor was there and I kept rebuilding my solution but no changes took place.
Then I remembered I was doing SharePoint feature development and had a deployed version of the feature on my box.  So my calls for the class were getting routed by the .net runtime to the version on the assembly in the GAC(c:\windows\assembly) not the local project version.  Ugh!
Once I retracted my feature and rebuilt the solution all was well again.
0 notes
jasonontheweb-blog · 14 years ago
Text
jQuery Content Rotator with the Cycle plugin
Requirements
- Rotator, previous, next, and pause buttons
- text to display current slide of total slides status
Solution
Plugin: http://jquery.malsup.com/cycle
Html:
<div id="featured-rotator">
    <div class="premier-item"></div>
    ...More divs as slides...
    <div class="premier-item"></div>
</div>
<div id="featured-rotator-controls">
    <span class="button" id="previous"><</span><span class="button"  id="pause">||</span><span class="button" id="next">></span> <span id="page-count"></span>
</div>
Script:
<script type="text/javascript">
    $(document).ready(function () {
        var premierCount = $("#featured-rotator div.premier-item").length;
        var currentItem = 0;
        var onAfter = function () {
            if (currentItem == 0 || currentItem >= premierCount) { currentItem = 1; }
            else if (currentItem < 0) { currentItem = premierCount; }
            else { currentItem++; }
            $("div#featured-rotator-controls span#page-count").html(currentItem + " of " + premierCount);
        };
        $("#featured-rotator").cycle({
            fx: 'scrollLeft',
            timeout: 5000,
            after: onAfter
        });
        $("div#featured-rotator-controls span#pause").click(function () {
            $("#featured-rotator").cycle('toggle');
        });
        $("div#featured-rotator-controls span#previous").click(function () {
            currentItem = currentItem - 2; //Move our place back 2 spots so moving forward one will put us in the right spot
            $("#featured-rotator").cycle('prev');
        });
        $("div#featured-rotator-controls span#next").click(function () {
            $("#featured-rotator").cycle('next');
        });
    });
</script>
Styles:
div#featured-rotator, div#featured-rotator-controls
{
    width:700px;
    background-color:beige;
    font-family:"Trebuchet MS", "Arial", "Verdana", "Sans-Serif";    
    font-size:10px;    
    color:#666;
}
#featured-rotator div
{
    vertical-align:top;    
}
#featured-rotator h2
{
    margin:10px 0 15px 0;
    color:#339;
    font-size:24px;
}
#featured-rotator a
{
    text-decoration:none;
    color:#339;
}
#featured-rotator-controls
{
    line-height:24px;
}
#featured-rotator-controls span.button
{
    cursor:pointer;
    padding:2px 5px;
    margin-right:3px;
    background-color:#666;
    color:#fff;
}
#featured-rotator div.premier-item div.premier-item-left, #featured-rotator div.premier-item div.premier-item-right { width:350px; float:left; }
#featured-rotator div.premier-item div.premier-item-right { clear:right; }
0 notes
jasonontheweb-blog · 14 years ago
Text
*Solved* Copy/Paste issues in VirtualBox Win2008 VM
I can't complain about my experience so far with using VirtualBox to run my SharePoint VMs.  VirtualBox is free and that's tough to beat.  I did run into an annoying issue where copy and paste suddenly stopped working between the guest and host in either direction.
I noticed that the VBox additions icon was no longer in my system tray so I tracked down the additions app in the following location, started it up and immediately copy and paste started working again.  Awesome!
Again if it's not running for you, you can find it in the install directory.  By default it is here: C:\Program Files\Oracle\VirtualBox Guest Additions\vboxtray.exe
18 notes · View notes
jasonontheweb-blog · 14 years ago
Text
*SOLVED* Internet connection issues in my VirtualBox VM
My laptop flaked out and rebooted itself while I had my VM open.  When I got the VM open again everything seemed fine except I couldn't pull up my SharePoint sites.  Then I found I had no connectivity at all.
After some digging I looked at the IE LAN settings and found that the use proxy box was checked but there were no settings there for the proxy.  I unchecked the box and left everything clear which was how my host was configured and everything started working again.
0 notes
jasonontheweb-blog · 14 years ago
Photo
Tumblr media
Guess the yellow screen of death happens to us al at some time.  This is the Microsoft addons site you get directed to from IE8 when you try to find more search providers.
0 notes
jasonontheweb-blog · 14 years ago
Text
SharePoint 2010 WCF Data Services(OData)
When the SharePoint 2010 updates were announced one of the features that really caught my eye was the addition of REST service endpoints.  REST endpoints means simple JavaScript interoperability to me.  In the 2007 product there were asmx web services available to work with from the client but these aren’t exactly fun to work with.
So what is REST?  Well I’ll leave that to Wikipedia.  To get to the rainbows and donuts moment though let’s take a look at what it’s like to work with the REST services API from JavaScript.
<code>
<div id="safety-stories"></div>
<script type="text/javascript">
                        $.getJSON("/safety/_vti_bin/listdata.svc/Pages?$filter=(ContentType ne 'Welcome Page')", function (data) {                                       
                                                var count = 0;
                                                $.each(data.d.results, function(i,result) {
                                                                        var title = result.Title;
                                                                        var comments = result.Comments ? "<br /><span class='alt'>" + result.Comments + "</span>" : "";
                                                                      �� var href = result.Path + "/" + result.Name;
                                                                          html = "<a class='summary-link' href='" + href + "'><p><h6>" + title + comments + "</h6></p></a>";
                                                                          $('#safety-stories').append($(html));
                                                });                                          
                         });       
</script>
</code>
This script block will retrieve all the pages from the safety site that not of content type “Welcome Page” and display their title with preview text(comments field value) and put it in the “safety-stories” div.
I hope you can see how powerful this is in creating custom page layouts. 
Now let’s talk about the downsides of using these services.  If you are using this on a publishing site be prepared that the field you absolutely must have may not be available.  For example the “Page Content” field is not available.  This means you need to force your authors to fill in the comments field with the text you wish to be displayed as a summary of the article in your page layout. 
This seems like a serious oversight to me, but if you consider the extra overhead of pulling the page content for each item in a big collection you can see why this was left out.
Instead of complaining about it I decided to take a look at what could be done to create a custom service that worked just like the listdata.svc but could be extended to include the fields I really needed to make this feature awesome.
So I started by looking at what Microsoft did to create the OOTB(out of the box) service.  To track this down I located the listdata.svc file in the 14 hive:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI folder.
Here are the contents of that file in their entirety:
<%@ServiceHost language="C#" Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressDataServiceHostFactory,      Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Service="Microsoft.SharePoint.Linq.ListDataService, Microsoft.SharePoint.Linq.DataService, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
This tells us all we need to track down the service code, but finding the service code in reflector has proven to be quite difficult.  I have to drop this effort for now as priorities have changed but I will come back to this when I have some more time.  In the meantime if you happen to run into the answer please mention it in the comments.
Thanks!
Jason
10 notes · View notes
jasonontheweb-blog · 14 years ago
Text
ASP.net Control Events Not Firing
I was working on an app that required generating buttons dynamically and setting up a command on them to pass an associated ID along.  For whatever reason I had to click the button twice to get it to work.
I spent nearly three days trying to track this down.
As it turns out my code looked something like this:
CreateChildControls
   Create some controls and panels
FindPeople
   Dynamically build search results with a button that when clicked serves as a selection
PersonSelectedButtonClicked
   Respond to the selection of a person
Well whenever I clicked the button the page would refresh due to postback but the click event never fired.
This is because the event needs to be applied to the control on post back, and the control needs to be available on the page to fire it's click event on post back.
So I updated the code to the following 
CreateChildControls
   Create some controls and panels
   Create the dynamicly generated controls if the user has already entered search criteria <-- This makes the button available to fire the click event on, without it you see the weird behavior I was seeing.
FindPeopleButtonClicked
   Dynamically build search results with a button that when clicked serves as a selection <-- still need this here to respond to the people search button click
PersonSelectedButtonClicked
   Respond to the selection of a person
0 notes
jasonontheweb-blog · 15 years ago
Text
"HTTP 400 Bad Request" error after creating a new site collection
This one cost me about half an hour of internet trolling for potential fixes. 
I remembered that on server 2008 the firewall tends to get in the way so I added a rule that allowed traffic in to the port of my new site.  This seemed to fix the 400 bad request error and I started getting the standard "this website is currently unavailable" type error message.
At this point I started to poke around in the IIS settings to see if something was configured in an odd way.  While reviewing the binding for the site in IIS I saw that the example host headers all had the domain in them.  In my case I had set the "Host Header" value during the process of creating a new site collection to the title of the site so when I tried to access the site after it was created I was directed to http://sitename:10000. 
I updated my host header to my machine name reset the web site and browsed to the new site's homepage and was greeted joyously by the default Contoso publishing site home page.
Update: Later on I was having issues connecting to the site from visual studio. I was able to create a new solution using my URL but when I hit F5 to debug my webpart I was getting the following error:
Error occurred in deployment step 'Recycle IIS Application Pool': Cannot connect to the SharePoint site: http://machinename:10000/. Make sure that this is a valid URL and the SharePoint site is running on the local computer. If you moved this project to a new computer or if the URL of the SharePoint site has changed since you created the project, update the Site URL property of the project.
Since the URL was right now I was really stumped until I looked in the event log and saw the following warning:
Alternate access mappings have not been configured.  Users or services are accessing the site http://sitename:10000 with the URL http://machinename:10000.  This may cause incorrect links to be stored or returned to users.  If this is expected, add the URL http://machinename:10000 as an AAM response URL.  For more information, see: http://go.microsoft.com/fwlink/?LinkId=114854"/>
Suprisingly this was a useful and informative error message.  Since I wanted to get rid of the http://sitename:port non-sense I actually ended up going to Central Administration --> Alternate Access Mappings and updating the http://sitename:10000 record to http://machinename:10000.
ince I actuall y
After that I tried to F5 debug again and everything finally worked as expected.
1 note · View note
jasonontheweb-blog · 15 years ago
Text
Configuring a SharePoint 2010 development environment in VirtualBox
While stepping through this process I essentially followed Sahil Malik's post on the matter so I won't recap that post here.
A few unique things did come up in the process though.  First while trying to get started with a new Windows Server 2008 install I got the following error:
Power up failed (vrc=VERR_VMX_MSR_LOCKED_OR_DISABLED, rc=E_FAIL (0X80004005))
Simon Hart had already found the fix for this issue which was to edit the BIOS settings and enable virtualization which was disabled for some reason.
Then when I got around to installing the SharePoint bits I got an error like the following:
osrchwfe.cab is corrupt, unable to continue
At the time I was hosting the iso within VirtualBox and installing from that drive mounted on my VM.  After googgling a bit on the issue it sounded like some folks were having better luck copying the files off the drive to the guest file system.  I tried that but had the same problem.
In the end I had to mount the SharePoint iso using VirtualCloneDrive on my host machine.  Copied the osrchwfe.cab file from msinstallbits/Global/search directory to my host machine.  Then I connected to my host machine's filesystem from the guest and copied the CAB file over top of the one I had local on my guest image.
I was then able to "retry" from within the installer and everything completed successfully.
0 notes
jasonontheweb-blog · 15 years ago
Text
Oddity in the SPSite constructor
I created the following method for taken user input of a site URL on a form and determining whether or not the URL is a valid site URL. public void SiteUrlChanged(SpDataQueryOptions options) { try { using(var site = new SPSite(options.SiteUrl)) { //If options.SiteUrl is an invalid url that starts with a valid one, the site object is still created _siteUrlValid = true; _view.SetSiteUrlFieldState(true, "Site url is valid!"); } } catch { _siteUrlValid = false; _view.SetSiteUrlFieldState(false, "Site url is invalid."); } SetButtonState(); } I would think that an error would be thrown if I gave the SPSite constructor an invalid URL but that was not the case. Instead I had to do the following: public void SiteUrlChanged(SpDataQueryOptions options) { try { using(var site = new SPSite(options.SiteUrl)) { //Added check to make sure we got back the site we were looking for if(site.Url != options.SiteUrl) { throw new Exception("Requested site not found."); } _siteUrlValid = true; _view.SetSiteUrlFieldState(true, "Site url is valid!"); } } catch { _siteUrlValid = false; _view.SetSiteUrlFieldState(false, "Site url is invalid."); } SetButtonState(); } At that point though the exception was being thrown because a valid SPWeb URL was coming back as the SPSsite URL. Then I realized that I was trying to solve a problem that didn’t exist. I wanted a SPSite but was trying to ensure that it was also a valid SPWeb url, but that check wasn’t really necessary. It doesn’t matter if the URL isn’t valid as an SPWeb, as long as we can turn it into a SPSite that’s all that matters in this case.
1 note · View note
jasonontheweb-blog · 15 years ago
Text
Find the bug
protected static PropertyInfo CommentTextProperty = RegisterProperty(typeof(Comment), new PropertyInfo("CommentText")); public virtual string CommentText { get { return GetProperty(CommentTextProperty, NoAccessBehavior.ThrowException); } set { SetProperty(CommentTextProperty, value); List tags = new List(); foreach (string s in value.Split(' ')) { if (s.Length > 0) { if (s[0] == '#') { tags.Add( s.Remove(0,1)); } } } LoadProperty(TagsProperty, tags); } } Became protected static PropertyInfo CommentTextProperty = RegisterProperty(typeof(Comment), new PropertyInfo("CommentText")); public virtual string CommentText { get { return GetProperty(CommentTextProperty, NoAccessBehavior.ThrowException); } set { SetProperty(CommentTextProperty, value); List tags = new List(); foreach (string s in value.Split(' ')) { if (s.Length > 0) { if (s[0] == '#') { var tag = s.Remove(0, 1).Trim(); if(tag.Length > 0) { tags.Add(tag); } } } } LoadProperty(TagsProperty, tags); } }
0 notes
jasonontheweb-blog · 15 years ago
Text
setTimeout Gotcha
<script type="text/javascript" src="http://www.host.com/shared/cache/jquery/142/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
                setTimeout(setDefaultText(), 5000);     ��
                function setDefaultText()
                {
                                $("iframe").each(function(index){
                                                alert($(this).attr("src"));
                                });          
                }
</script>
Everything seemed to be setup correctly and my function was firing but there was no delay.  What was the problem?
Update:  The first parameter of the setTimeout method is a string.  Putting the method call there without the quotes will just cause the method to be called when the line is executed.
0 notes
jasonontheweb-blog · 15 years ago
Text
Kindle vs nook
While reading this post from Fast Company that covers the newly released Kindle one particular statement stuck out to me.
The Nook, the Kindle's closest competitor, also packs an Android-powered color touchscreen, which opens it up for lots more development and extras than the Kindle is capable of, including video playback, advanced games, messaging, and more.
I think this is a con for the nook.  The main reason I don't get reading done on my iPhone is because there is just too many other things I could be doing on the phone.  When I'm using a eReader I don't want people messaging me, or email notifications pinging, or anything else...I want to read.
0 notes
jasonontheweb-blog · 15 years ago
Text
MVC Model Binding part of a form
If you want to bind part of a form to one parameter, and the other part to another you have to explicitly tell MVC which properties to map to each parameter.  If you refactor the controller and change the parameter name then an error won't be thrown but binding will just stop working.  Here is the proper way to do it:
<form> <input type="hidden" name="foo.ID" /> <input type="hidden" name="bar.ID" /> </form> public ActionResult MyActon(Foo foo, Bar bar) { //Do stuff }
0 notes
jasonontheweb-blog · 15 years ago
Text
Baby Steps: Rails3 with MongoDB
Got my first crud app up and running tonight. Hardest thing was tracking down the current resources/best practices. Apparently the generate syntax changed in rails3, I spent two hours trying to figure out why my rails app generator wasn't working right. Once the app was up and apparently writing to the db I had to double check that the data was actually being saved but I couldn't figure out how to view in the mongo js console. Turns out you have to set the db then query for your data.
0 notes
jasonontheweb-blog · 15 years ago
Text
Acceptance testing with Cucumber
I'm hoping to wrap my arms around Cucumber because the idea of executable requirements that run against the solution you're delivering as a developer is awesome. This can clear up a lot of the assumptions on both sides and give the business a sense of the wild cases you've planned for, and the ones you haven't. http://cukes.info
0 notes