Archive for the 'web' Category

About a year ago my lady picked up a book called Chicago’s Best Dive Bars: Drinking and Diving in the Windy City written by Jonathan Stockton. From time to time I pick up the book when I’m in a mood to find a cool bar as an alternative to the standards that I frequent in Lakeview and Lincoln Park. I’ve been to some of them and if I am lucky enough I will be able to hit up all of them on the list some day.

Published by IG Publishing in Brooklyn the book is described by IG Publishing as:

Chicago’s Best Dive Bars features opinionated reviews of over 90 of the grungiest and grittiest drinking establishments in the Windy City. If you want to avoid the tourist traps listed in those “other” bar guides and find out where the “real” people do their drinking, then Chicago’s Best Dive Bars, like its New York and San Francisco predecessors, is the drinking person’s guide to the delightfully filthy underside of Chicago bar life.

Continue on to the dive bar map.

Whats up? Url rewriting is a pretty cool thing to have. [especially when people ask you for it] There’s a lot of requests by people who want to implement full on url rewriting or extension less urls in SharePoint 2007. After messing around for a little bit it, I came up with a good way to do it. When I was looking for examples on the web there were a lot of people saying that it couldnt be done. I thought, wtf, serial? But in the end it actually didn’t take much to implement it. Here’s an HttpModule that I wrote to do the work.

The key pieces are the this.app.BeginRequest += new EventHandler(app_BeginRequest) which
steps in front of the request and allows the module to get its redirect on.

And HttpContext.Current.RewritePath(redirect, false); will push the necessary headers n such forward so that the receiving .aspx page will understand how to correctly post back.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Security.Cryptography;
using System.Configuration;
using System.Threading;
using System.IO;
using System.Security;
using System.Security.Principal;

namespace ScaredPanda
{
    public sealed class RewriteHttpModule : IHttpModule
    {
        HttpApplication app = null;
        ///
        /// Initializes the httpmodule
        ///
        public void Init(HttpApplication httpapp)
        {
            this.app = httpapp;
            this.app.BeginRequest += new EventHandler(app_BeginRequest);
        }

        public void app_BeginRequest(Object s, EventArgs e)
        {
            try
            {
		//determine if the income request is a url that we wish to rewrite.
		//in this case we are looking for an extension-less request
                string url = HttpContext.Current.Request.RawUrl.Trim();
                if (url != string.Empty
                    && url != "/"
                    && !url.EndsWith("/pages")
                    && !url.Contains(".aspx")
                    && url.IndexOf("/", 1) == -1)
                {
                    //this will build out the the new url that the user is redirected
                    //to ie pandas.aspx?pandaID=123
                    string redirect = ReturnRedirectUrl(url.Replace("/", ""));

		    //if you do a HttpContext.Current.RewritePath without the 'false' parameter,
                    //the receiving sharepoint page will not handle post backs correctly
		    //this is extremely useful in situations where users/admins will be doing a
                   //'site actions'  event
                   HttpContext.Current.RewritePath(redirect, false);
                }
            }
            catch (Exception ex)
            {
                //rubbish
            }
        }
    }
}

Right now we are creating some new php sites and I ran into the problem where I wanted to post an array or collection of input items from php page to php page. The solution that I found here works perfectly.

We have a collection of <input> items and when posted across the wire I wanted to loop through the collection. This code is does just that.

page 1 contains some <input> items:

<input name=”item_1″ id=”item_1″ />
<input name=”item_2″ id=”item_2″ />
<input name=”item_3″ id=”item_3″ />

page 2 contains this php code:

foreach ( $_POST as $varname => $postitem )
{
    echo ($varname."".$postitem);
    echo("<br />");
}

easy as that.

We have been creating multiple MOSS2K7 sites in our development environment and then moving them up to production servers, as you usually do in this game. Instead of creating them by hand I have been using the stsadm.exe -o backup/restore functionality which works bichenly. But, there are a few problems that I have run into. Part of the problem when using the backup/restore functionality is that SharePoint page layouts hold onto the old server information. After doing a successful restore of one of my MOSS2K7 site I tried to edit the page settings through the Page — Edit Page Settings link when I got the error “Value does not fall within the expected range”. This problem is because the newly restored site is holding onto an old site definition and is unable to find the old site def. If you look at the page layout through the Content Structure page you can see the old server referenced. A while ago I came across some code that fixes this issue. However I can’t for the life of me find where the hell I found it. So if you recognize some of the variable names let me know so I can give you some credit. The code wasn’t written as a web part but as a command line utility, so for those who don’t have access to the server this code wasn’t much of use. So czech out the web part that I created, drop this onto your page and the part loops through all the sites and subsites in your site and it fixes up the layout urls.

*Note that if you are running this code from the web part that the code must be run using the SPSecurity.CodeToRunElevated objects. If the code is not run with elevated privileges you will receive an “access” error.

using System;
using System.Text;
using System.ComponentModel;
using System.Collections.Generic;
using System.Security.Permissions;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Publishing;
namespace ScaredPanda.Web.UI.WebControls.WebParts
{
    public class FixLayoutUrls : System.Web.UI.WebControls.WebParts.WebPart
    {

        protected override void CreateChildControls()
        {
            SPSecurity.CodeToRunElevated ElevatedCode = new SPSecurity.CodeToRunElevated(CodeToRunElevated);
            SPSecurity.RunWithElevatedPrivileges(ElevatedCode);

            base.CreateChildControls();
        }

        protected void CodeToRunElevated()
        {
            try
            {
                using (SPSite oSite = new SPSite(SPContext.Current.Web.Url))
                {
                    Context.Response.Write(oSite.RootWeb.Url);
                    FixPages(oSite.RootWeb);
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void FixPages(SPWeb oWeb)
        {
            try
            {
                if (!PublishingWeb.IsPublishingWeb(oWeb)) return;

                PublishingWeb pw = PublishingWeb.GetPublishingWeb(oWeb);
                SPListItemCollection oList = pw.PagesList.Items;

                string sSiteUrl = oWeb.Site.Url;
                oWeb.AllowUnsafeUpdates = true;
                this.Context.Response.Write("Processing " + oWeb.Title + "(" + oList.Count.ToString() + " pages)...");

                foreach (SPListItem oPageItem in oList)
                {
                    string s = (string)oPageItem[FieldId.PageLayout];
                    if (s != null && !s.StartsWith(sSiteUrl))
                    {
                        this.Context.Response.Write(”Fixing ” + oPageItem.Title + ” (” + oPageItem.Url + “)”);
                        oPageItem[FieldId.PageLayout] = sSiteUrl + s.Substring(s.IndexOf(”/”, 9));
                        oPageItem.SystemUpdate();
                    }
                }

                foreach (SPWeb oSubWeb in oWeb.Webs)
                {
                    FixPages(oSubWeb);
                    oSubWeb.Dispose();
                }
            }
            catch (Exception ex)
            {
                this.Context.Response.Write(”Layout fix failed at site: ” + oWeb.Title + “”);
                this.Context.Response.Write(ex);
            }
        }
    }
}
    Tere! Scrrd panda - a place for my friends and family to see what i'm up to; and an occasional code post.
  • 89.3 The Current

  • recently written

  • categories

  • Archive