Madhawa Learns To Blog : C#, Java

.net, c#, java,sql, OOAD and more mad memory dumps...

  Home  |   Contact  |   Syndication    |   Login
  47 Posts | 0 Stories | 57 Comments | 15 Trackbacks

News

Archives

Post Categories

Blog Roll

Hang Outs

My old blog

Friday, January 11, 2013 #

Very good insight on using "AllowUnsafeUpdates" in SharePoint object model.

http://hristopavlov.wordpress.com/2008/05/21/what-you-need-to-know-about-allowunsafeupdates-part-2/


Wednesday, October 24, 2012 #

If you have tried Sharepoint discussion boards, you already know that you cannot offer a PROPER forum experience with it. It's still very primitive and it will take considerable time and effort you to extend and customize.

Fortunately I found that there are some third party solutions, and Lightning Storm Forum is a very nice alternative. I'ts not free but not that expensive either.

You can try it for free and can have a proper forum running in your website withing less than an hour :)

http://lightningtools.com/products/storm-forums/

Wednesday, September 7, 2011 #

Very useful article by Wayne Hartman.

http://blog.waynehartman.com/articles/84.aspx

 


Wednesday, August 24, 2011 #

Yesterday I realized that non of my custom lists enforce content approval by default. That really worried me as 90% of the data we display in the web site which I'm working on are coming from custom lists.

Enabling this manually is a piece of cake but I wanted to include this in the list definition.

After some research and testing I found out that there are 2 places you have to configure.

You have to set ModeratedList="TRUE" for List element and EnableModeration="True" for ListTemplate element in your schema files.

Remember this works only for new lists you are creating from these definitions but wouldn't affect lists which already exist.


Wednesday, June 15, 2011 #

These days I'm working on a CMS solution and I had all my list definitions and list instances in one feature, so everything was working fine.

But its not ideal as each time I change the list definitions I have to de-activate and re-activate the whole feature. And each time I do that the default data I have defined in list definitions are duplicated.

So I created another feature for list instances but its giving the following error when trying to activate.

"GetUserListSchema(): Failed to get the list schema XML for feature"

Problem was as I was using the element files from the old feature I hadn't defined the "FeatureId" in the "ListInstance" schema. So remember if you have list instances in a different feature than your List definitions, you gotta give the "FeatureId" in the "ListInstance" schema. Its optional if you have all in one feature.


Wednesday, June 23, 2010 #

Going over all the w3wp processes in task manager is frustrating if you wanna do this frequently :). So here it is.

taskkill /F /IM w3wp.exe /T

Works in the command line and PowerShell as well.


Monday, August 17, 2009 #

        /// <summary>
        /// Add Permission Level to a Sharepoint user group collection
        /// </summary>
        /// <param name="spWeb">The sp web.</param>
        /// <param name="permissionName">Name of the permission.</param>
        /// <param name="groupCollection">The group collection.</param>
        public static void AddPermissionsToGroupCollection(SPWeb spWeb, string permissionName, string[] groupCollection)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                try
                {
                    //Allow updating of some sharepoint lists, (here spUsers, spGroups etc...)
                    spWeb.AllowUnsafeUpdates = true;

                    SPRoleDefinition roleDefinition = spWeb.RoleDefinitions[permissionName];

                    foreach (string group in groupCollection)
                    {

                        SPGroup spGroup = spWeb.Groups[group];

                        SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
                        SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;

                        roleDefBindings.Add(roleDefinition);
                        spWeb.RoleAssignments.Add(roleAssignment);

                        roleDefinition.Update();
                    }

                }
                catch (Exception ex)
                {
                    //Error handling logic should go here
                    throw ex;
                }
                finally
                {
                    spWeb.AllowUnsafeUpdates = false;
                }

            });
        }

Ok this is it.

Well... I called above method from "FeatureActivated" event of a feature. For "FeatureDeactivating" event I tried to achieve the contrary to this, delete a permission level from a user group. But didn't succeed. :( 

If you have any idea pls let us know.Thanks in advance.


Saturday, August 1, 2009 #

 public static List<string> GetChoiceFieldValues(string listName,string fieldName, string siteCollection, string webSite)
        {
            List<string> fieldList;

            SPSite spSite = null;
            SPWeb spWeb = null;

            try
            {
                if (siteCollection != null)
                    spSite = new SPSite(siteCollection);
                else
                    spSite = SPContext.Current.Site;

                if (webSite != null)
                    spWeb = spSite.OpenWeb(webSite);
                else
                    spWeb = spSite.OpenWeb();

                SPList spList = spWeb.Lists[listName];

                SPFieldChoice field = (SPFieldChoice)spList.Fields[fieldName];

                fieldList = new List<string>();

                foreach (string str in field.Choices)
                {
                    fieldList.Add(str);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw;
            }
            finally
            {
                if(spWeb != null)
                    spWeb.Close();

                if(spSite != null)
                    spSite.Close();
            }

            return fieldList;
        }

 


Monday, June 29, 2009 #

You know what happens when we change the name of a SharePoint server right? It simply won’t work again unless you run the SharePoint Server configuration wizard.

So what would happen if you do the same for the SSRS (SQL server reporting services) server? Some say you might not be able to connect to the reporting services again. I changed my reporting server’s name and still was able to create reports and do some other things. But clearly there were some problems. I tried to get support from my colleagues who were already familiar with SSRS but with no luck.

After some googling I found below link looks promising. But alas… it didn’t resolve my prob.

http://msdn.microsoft.com/en-us/library/ms345235(SQL.90).aspx

If I point my problem clearly, when I try to do “Configure report server - > Initialization” it shows me old machine name (name before I rename it) which will causes lots of problem in future. (That was according to my colleagues and I don’t know what those problems would be as this is the first time I’m gonna use SSRS)

Then I tried to create a new reporting server database through “Configure report server - > Data Setup”.


Guess what? It worked and saved my day!


Thursday, January 22, 2009 #

Today I had to work on a project which uses VS2008 and SQL Server 2008. I haven't used SQL2008 but had used VS2008 a little bit. When I tried to install SQL2008 (Developer edition) got this strange error which says "Microsoft .NET Framework 3.5 installation has failed. SQL 2008 Setup requires .NET 3.5 to be installed."

Strange thing is I had installed .NET 3.5 in the VPC upfront. Actually you are installing .NET 3.5 when you install VS2008 right?

Anyway I tried to resolve this using,

1. Uninstall .NET 3.5 and try install SQL 2008 (SQL 2008 setup comming with .NET 3.5 installation)

2. Reinstall .NET 3.5 and install SQL 2008

3. Reinstall .NET 3.5, service pack and install SQL 2008

Yes... I failed. I can't remember what other things I tried. :)

So then I went for other possible option, that is to connect to an existing SQL2008 server through VS2008. Then I got this damn error message.

 "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported.".

But fortunately this time I got the resolution. You had to install <a href="http://download.microsoft.com/download/6/7/0/670ce765-4c9b-4620-902f-b9fc9a7c3c2d/vs90-kb945855.exe">vs90-kb945855.exe</a>. Then you can connect to SQL2008 from VS2008.

But still I didn't get an answer for my first prob. If anyone knows the answer pls drop the solution here. Thanks in advance.

 


Tuesday, November 18, 2008 #

        /// <summary>
        /// Add a user to a Sharepoint group
        /// </summary>
        /// <param name="userLoginName">Login name of the user to add</param>
        /// <param name="userGroupName">Group name to add</param>
        private void AddUserToAGroup(string userLoginName, string userGroupName)
        {
            //Executes this method with Full Control rights even if the user does not otherwise have Full Control
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                //Don't use context to create the spSite object since it won't create the object with elevated privileges but with the privileges of the user who execute the this code, which may casues an exception
                using (SPSite spSite = new SPSite(Page.Request.Url.ToString()))
                {
                    using (SPWeb spWeb = spSite.OpenWeb())
                    {
                        try
                        {
                            //Allow updating of some sharepoint lists, (here spUsers, spGroups etc...)
                            spWeb.AllowUnsafeUpdates = true;

                            SPUser spUser = spWeb.EnsureUser(userLoginName);

                            if (spUser != null)
                            {
                                SPGroup spGroup = spWeb.Groups[userGroupName];

                                if (spGroup != null)
                                    spGroup.AddUser(spUser);
                            }
                        }
                        catch (Exception ex)
                        {
                            //Error handling logic should go here
                        }
                        finally
                        {
                            spWeb.AllowUnsafeUpdates = false;
                        }
                    }
                }

            });
        }

 

Here in this method you have to set "spWeb.AllowUnsafeUpdates = true" to allow updating some sharepoint lists.


Tuesday, November 11, 2008 #

Check these really good articles by James Tsai.

Understand SharePoint Permissions - Part 1. SPBasePermissions in Hex, Decimal and Binary - The Basics

Understand SharePoint Permissions - Part 2. Check SharePoint user/group permissions with Permissions web service and JavaScript

Thanks Suranja for sending me these links.

 


Tuesday, September 2, 2008 #

I have a small question for sharepoint experts. :)

Can we deploy a Content Type as a feature with some extended settings like "Workflow settings" and "Information management policy settings"?

If so please enlighten me on how to do that.


Monday, September 1, 2008 #

Type below in the command line replacing <MC name or IP> with the machine name or IP you want to connect. This works with WinXP and Vista.

mstsc -v:<MC name or IP> /f -console

Updated:

:D There is a easy way. Just type mstsc /console in the command prompt.


Tuesday, August 26, 2008 #

STSDEV is a simple tool for SharePoint developers. It helps you to create SharePoint projects (with solutions precisely) and deploy templates and components into the SharePoint 2007 platform.

http://www.codeplex.com/stsdev

This tool creates project and solution in same name and in the same folder. We all know we never put the solution and project files in the same folder and never use same name for the solution and the project. Unfortunately we didn’t find a way of changing those and use the tool after since it gives errors. I found a very easy way of tweaking that from changing small line in the source code or changing a line in the generated .target file.

And furthermore I have changed the tool to support for supplying a different project name when creating a solution and now we are using it in our SharePoint project.

BTW I'll explain how to tweak the tool to use separate source folder for project by a small change in the source code in next post. Until then play with the tool and have some fun.

If you want that version of the tool with source code please email me.