Technical blog archive

.NET King Technical blog
 This is the real Alireza! jumping from one technology to another every day. Here you can read my technical blogs. Just select the right category and enjoy.
 By the way, don't miss the general blog.


Visual Studio 2008, ASP .NET and Crystal Report (2/12/2010)

It is interesting that the article "Crystal Reports in ASP .NET Web Applications" is the most viewed page on my website. Although it is not the latest version of Crystal Reports and Visual Studio, the code is still valid with Visual Studio 2008. Now with YouTube and all new video technologies I am thinking of making a video about using Crystal Reports in ASP .NET 3.5 and new components available in the new product.
It is coming soon, Stay tuned.
Cheers
Alireza
 

1 comments by now. Add your comments
How to change the size of Quick Launch menu in SharePoint (2/8/2010)

Assuming that you are using the default master page, the size of the quick launch menu is fixed 150X400 pixels. If the content is anything more than this size it automatically adds scroll bars. To change size of this area open the default.master in SharePoint designer. Go to the code view and find SharePoint:SPRememberScroll tag. The style attribute has the size of the quick launch area.

Here is the default value

Style="overflow: auto;height: 400px;width: 150px; "

 

Simply change it to anything you like:

Style="overflow: auto;height: 400px;width: 250px; "

Cheers
Alireza

0 comments by now. Add your comments
First Look at SharePoint 2010 – Presented by Savash Alic (10/21/2009)
If you live in Toronto, this is a great chance to get familiar with this new monster called SharePoint 2010. Don't miss it. See the event details here.
Cheers
Alireza
0 comments by now. Add your comments
.NET Framework is 7 years old today (2/13/2009)
Seven years ago on February 13, 2002 Microsoft released the first version of .NET Framework . Lets have a quick look at the .NET Framework evolution:
In 2002 Version 1.0 was released with Visual Studio .NET
In 2003 .NET Framework 1.1 was released embeded in Windows 2003 Server. (Operating system relies on .NET Framework)
In 2005.NET Framework 2.0 was releases with Visual Studio 2005 and SQL Server 2005. (Relational Database engine relies on .NET Framework)
In 2006 .NET Framework 3.0 was released enbeded in Windows Vista and Windows Server 2008. (Client desktop relied on .NET Framework)
In 2007 Microsoft releases .NET Framework 3.5 with Visual Studio 2008 and Windows 7.
Happy Birthday .NET. You are growing fast!
Cheers
Alireza
1 comments by now. Add your comments
SQL Server 2008, Ideal for developers (2/11/2009)
I read this article some time back and I really enjoyed it. It reveals the sexiest features of SQL Server 2008 for techies and especially developers. Can anybody show me an articled that explains the value of SQL Server 2008 for executies? In better word I need something that can explain the value of this amazing product for decision makers who are not technical.
Cheers
Alireza
0 comments by now. Add your comments
Is SharePoint branding important? (2/10/2009)
It sounds like a silly question but look at the answer from developers’ perspective.
“Branding!? Is branding giving you any functionality? So why shall I waste my time on branding?”
A trainer will possibly say:
“Branding and UI customization makes the product look different from the original look different and makes the learning costly”
Here is my challenge: “Is SharePoint a product?” I can say MOSS is a product but most of the developers look at WSS just as a platform. When a developer builds a product on SharePoint platform, then it is not SharePoint. Now branding gives context to data and makes turns it into information. The branding that brings the user to the right context is critical to deliver the information in the right way and result in right reaction from information workers. In better word just because we are not graphic desighers doesn’t mean that we can take their work for granted!!!!
Cheers
Alireza
0 comments by now. Add your comments
SharePoint Restore Error (1/25/2009)

Your backup is from a different version of Windows SharePoint Services and cannot be restored to a server running the current version. The backup file should be restored to a server with version '12.0.0.6335' or later.

It sounds like an odd error but lets face it. STSADM backups are not service-pack independent. It just reminds me of restoring SQL Server system databases. Remember that you need to have identical service packs on source and destination of the backup. Otherwise your restore shows you this.

Check this little post by Aaron Saikovski to get your exact solution.

Cheers
Alireza

0 comments by now. Add your comments
From a Product called SharePoint to Basic Concepts (1/25/2009)

 For years I was blaming Microsoft Official Curriculum for different courses for one very simple reason. The courses are technology oriented. In better word you go through all the .NET courses and exams and earn your MCSD credential but still you don't know design patterns. You become an MCDBA without having a good grasp of Normalization and RDBMS. Now guess what? Somebody is an MCDBA who knows SQL Server inside out, yet sucks at delivering a reasonable database model for a solution. This becomes even worse when it comes to SharePoint content management. I have worked with lots of clients that start with SharePoint implementation and in no time end up with a file garbage dump rather than a content management solution. It is obvious, because we never gave them the content management basics. Imagine building a house by just trial and error, without an architect in place.

 Now take a look at this course content for a change:
Architecting Web Content Management Solutions with Microsoft Office SharePoint Server 2007 

Hey, it seems like Microsoft response to this need. Or look at this one:

Architecting and Planning the Search Capability in Microsoft® Office SharePoint® Server 2007

Actually this is not a new course approach, I have delivered database modeling from Microsoft Official Curriculum 6 years ago. I only believe these courses are not marketed well simply because most of the clients see Microsoft as pure technology provider. SharePoint is a new product with new concepts around it. Consider basics before you get into the technology!

 Cheers
Alireza

0 comments by now. Add your comments
Creating SharePoint Permission levels programmatically (C#) (1/24/2009)

Imagine you are asked to create a custom permission level for all the sites in a MOSS/WSS site collection. I mean one of these things that you see in the below screen capture! Sounds silly, because you can easily click on the "Add a Permission Level" and finish the job. Now imagine that sites do not inherit the permission levels and you have only 200 sites in the site collection. Now it sounds like a nightmare.

Now here are the magic C# words to break the spell! Your code should automate this step.

Here are some important considerations.
1. You have 200 sites and there is no guarantee that all sites are following the same role inheritance setting. In better word some sites may inherit the roles and some don't. It is obvious that you cannot and you don't need to create this role in the sites that they inherit.
2. You have to create this role in the root website of the site collection.

Take a look at this code.

    SPWeb myWeb = mySite.AllWebs[i];
    if (myWeb.HasUniqueRoleDefinitions || myWeb.IsRootWeb)
    {
 
        try
        {
            MessageBox.Show(myWeb.Title);
            myWeb.AllowUnsafeUpdates = true;
            SPRoleDefinition rd = new SPRoleDefinition();
            rd.BasePermissions = SPBasePermissions.ManageLists |

            SPBasePermissions
.CancelCheckout |

SPBasePermissions.AddListItems
| SPBasePermissions.EditListItems |

SPBasePermissions.DeleteListItems;
      rd.Name = "Custom role 01";
      myWeb.RoleDefinitions.Add(rd);
      myWeb.Update();
  }
  catch (Exception ex)
  {
            MessageBox.Show(ex.Message, myWeb.Title);
  }
}

 Don't forget to import:
using Microsoft.SharePoint;

Cheers
Alireza

3 comments by now. Add your comments
How to read SharePoint list items attachments programmatically? (1/7/2009)

See the following code snippet:

  SPSite mySite = new SPSite("http://sharepoinsiteaddress");
  SPWeb myweb = mySite.OpenWeb();
  SPList myList = myweb.Lists["Announcements"];
  SPListItem myListItem = myList.GetItemById(1);
  foreach (String attachmentname in myListItem.Attachments)
  {
   String attachmentAbsoluteURL =
   myListItem.Attachments.UrlPrefix // gets the containing directory URL
   + attachmentname;

   // To get the SPSile reference to the attachment just use this code
   SPFile attachmentFile = myweb.GetFile(attachmentAbsoluteURL);

 

   // To read the file content simply use this code
   Stream stream = attachmentFile.OpenBinaryStream();
   StreamReader reader = new StreamReader(stream);
   String fileContent = reader.ReadToEnd();

   // assuming that file is a text attachment
   MessageBox.Show(fileContent);
  }

I think the code is self descriptive. Just some points to remember:

  • Attachments collection of SPListItem object is not SPFile. It is string that only represents file name.
  • Most of the time just a hyperlink to the attachment serves the purpose for the web UI design.
  • I used a windows application to present this code, you may implement it in any project.
  • Don't forget the required namespaces.
    • using System.IO;

    • using Microsoft.SharePoint;

Enjoy!
Alireza

2 comments by now. Add your comments
CamStudio or Camtasia (1/4/2009)

 For a long time I was using Camtasia Studio for screen capture and recording online presentations. I always liked this software becasue it doesn't interfere with the other applications on the dev server that is usually heavily loaded with lots of different software solutions and services and it doesn't slow down the server as well. It provides a very strong sound and movie editing studio but you need to pay 299 USD for the license.

 My new choice is CamStudio. It doesn't give you a fancy movie editing studio, but it happily works on Windows 2003 server loaded with MOSS 2007 and BizTalk 2006. It doesn't slow down any process and it is FREEEEEE!!! Ok, for the editing studio go for Microsoft Movie Maker and you are all set.

Cheers
Alireza

1 comments by now. Add your comments
Get rid of HTML and XML tags (5/30/2008)

 When you work with word xml files and locate a field in the schema what you read usually contains XML decorating tags that most probably you don’t need them in your code. How can we get rid of them?
It is pretty simple. Brush up your .NET knowledge and remember we have a class called Regex which is a short name for Regular Expression object. Using Regex you can simply define a pattern for XML or HTML tags. This pattern will be something like this: "<[^>]*>".
The very same Regex class has Replace function that works just like Replace in String class. Having them all together in C# you will have a code like this:
 

  public string RemoveTags(String originalMessage)

  {

      Regex rgx = new Regex("<[^>]*>");

      return rgx.Replace(originalMessage, "");

  }

This function simply gets an HTML/XML String and returns pure text. Don’t forget to add
using System.Text.RegularExpressions;
to your file header.
Enjoy
Alireza
 

2 comments by now. Add your comments
 

 -