Thursday, March 28, 2013

Fixed Position Div Vertically Only

Recently a client asked for a footer on a portal, that had a fixed width, was fixed on the screen (so it would stay on the screen when scrolling up and down), but wanted to make sure if the browser window was small enough where horizontal scrolling was needed, that the footer would scroll.

CSS position:fixed just wasn't going to cut it alone, as when you set that fixed position, it basically ignores all scrolling, both vertical and horizontal.

I ended combining CSS with some jQuery. Assuming our footer is in a div:

<div id="footer">Something in my footer</div>

I applied this CSS

.footer {
    position:fixed;
    margin:auto;
    width:900px;
    bottom:0px;
    height:30px;
}

And then I put this in my javascript file (you could put it in script tags too)


//Keeps the header and footer on the screen and scrolling horizontally
$(window).resize(positionFooter);
$(window).scroll(positionFooter);

function positionFooter() {
    if ($(window).width() < 900) {
        $('#footer').css('left', -$(window).scrollLeft());
    }
    else {
        $('#footer').removeAttr('style');
    }
}

This attaches an the function positionFooter() to the window scroll event as well as the resize event. The function itself checks to see if the width of the window is large enough to fit my footer (900 in this case) and if it isn't, it sets the left attribute as an inline style on the footer div making it move to the left simulating scrolling. If the window is large enough, it ensures the inline style tag is removed so the margin:auto will work again.

Worked like a charm.

Thursday, March 14, 2013

HTML5 using JavaScript and CSS3 Microsoft Cert

I passed the HTML5 Microsoft Certification exam this morning. I'm really impressed with Microsoft and how they've really embraced jQuery and the open source community with their latest exams. I'm excited to continue on the MCSD track for SharePoint 2013. From what I hear there will be one more exam that I can take to upgrade my MCPD but I think I'll probably take the other two exams that may be coming down the line. I've heard that they should be released in beta around the first week in April.

- Owen Runnals
SharePoint Practice Manager @ General Networks Corp

Thursday, March 7, 2013

Visual Studio ignoring Step In and Referencing GAC DLL instead of local copy

I've been working on a large project for SharePoint 2010 and we just started using Visual Studio 2012. I needed to reference and use a SharePoint helper project that I wrote in the past so I added it to my solution (as I knew I'd need to update some of the functions) and then referenced it in my new class.

When building and trying to step into methods in my SharePoint helper project VS2012 was ignoring my Step In and was just stepping over.

I finally found out that VS was ignoring my direction to copy the referenced dll locally and was instead loading the dll from the GAC. I hadn't incremented the assembly version but had changed the code of the SharePoint helper so I couldn't even manually load the symbol file.

So all I did was increment the assembly version on the SharePoint helper project and immediately it copied the dll locally and stepped in properly during debugging.

Lesson learned!

SharePoint 2013 Provider Hosted App - 401 Unauthorized Error

I've been working on some SharePoint 2013 apps and was building a Provider Hosted app this evening. I followed the step by step instructions in this Microsoft Article and all was going well. Then I tried testing my app and got a 401 unauthorized error.

I searched around and found a few reasons for this error:
- User Profile - it seems you need to have a User Profile created for the user using the app, this wasn't it as I had a user profile.
- Permissions - Your app may be trying to access things it hasn't been granted permission to. This wasn't it either as my app wasn't doing anything, just showing a page.
- Anonymous Access - Your app needs to be able to verify your identity so that it can authorize you in SharePoint. This wasn't my problem either as I was just using F5 to run it, so VS was dynamically creating a web app.
- Certificate Issue - You need to add your app certificate to the trusted certificate store. I had done this through PowerShell earlier but decided to check it out.

Ends up I overlooked the text in the Microsoft Article that states the issuer id needs to be all lowercase letters. Visual Studio's Guid generator alwasy provides all caps and I just copy/pasted.

I removed it and readded and all worked perfectly!