Madhawa Learns To Blog : C#, Java

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

  Home  |   Contact  |   Syndication    |   Login
  45 Posts | 0 Stories | 50 Comments | 15 Trackbacks

News

Archives

Post Categories

Blog Roll

Hang Outs

My old blog

Wednesday, September 07, 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 01, 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 02, 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 01, 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.

 


Monday, August 25, 2008 #

One of the main things you should consider if you believe in good coding is error or exception handling. When it come to programming languages, now all popular object oriented languages have try, catch method to handle an exception.

We can put our code (which might gives errors or exceptions) inside the try block and error handling code in the catch block. This has become the de-facto of error or exception handling now.
But when it comes to T-SQL we hadn’t got that luxury. Error handling in T-SQL was always tedious and tricky job. Most of the time we used not to handle the error at the T-SQL level but handling it in the upper most level. (data access layer or business layer, handling database errors in business layer is a totally wrong practice)

But now in SQL 2005, 2008 you have proper error handling mechanism just like in modern OO languages. You can use try catch in the stored procedures and functions. Actually I knew that I can use try catch in stored procedures but only today I got to know about a more interesting method we can use.

After catching an error what we can to do was a question for me. If it’s in C# or Java we can log the error and may be throw a customized exception to the next layer. (There are so many options in handling errors)
Can you remember throw exception in C#? Of cause you know it. :) Well… we can do the same in T-SQL using RAISERROR function.

Using the RAISERROR is as follows,

BEGIN TRY
    -- RAISERROR with severity 11-19 will cause execution to
    -- jump to the CATCH block.
    RAISERROR ('Error raised in TRY block.', -- Message text.
               16, -- Severity.
               1 -- State.
               );
END TRY
BEGIN CATCH
    DECLARE @ErrorMessage NVARCHAR(4000);
    DECLARE @ErrorSeverity INT;
    DECLARE @ErrorState INT;

    SELECT
        @ErrorMessage = ERROR_MESSAGE(),
        @ErrorSeverity = ERROR_SEVERITY(),
        @ErrorState = ERROR_STATE();

    -- Use RAISERROR inside the CATCH block to return error
    -- information about the original error that caused
    -- execution to jump to the CATCH block.
    RAISERROR (@ErrorMessage, -- Message text.
               @ErrorSeverity, -- Severity.
               @ErrorState -- State.
               );
END CATCH;

Pretty good ha…
You can follow up this more in
MSDN.

 

 


Tuesday, January 29, 2008 #

Well... After 6 months I’m gonna do it again. I don’t know people who used to visit my blog still are doing that. Anyway will tell ya what happened in last 6 months later. :D


Well today I was working on deploying a SharePoint site in 64 bit server. This is the first time I’m putting my hands on x64 bit machines.  If you are used to do or want to do SharePoint deployments and never done that in 64 bit servers just keep in mind below.

There are 2 programming files folders in 64 bit machines. Normal "programming files" folder for x64 bit programs and "programming files (x86)" for 32 bit programs. So when you are using script files or solutions  (wsp files) for deployment make aware of this. More info will follow…. :)