Thursday, September 22, 2011

Remove HTML tags from a string using C#

public static class RemoveHtmlFromString
{
    /// <summary>
    /// Remove HTML from string with Regex.
    /// </summary>
    public static string StripTagsRegex(string source)
    {
 return Regex.Replace(source, "<.*?>", string.Empty);
    }

    /// <summary>
    /// Compiled regular expression for performance.
    /// </summary>
    static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);

    /// <summary>
    /// Remove HTML from string with compiled Regex.
    /// </summary>
    public static string StripTagsRegexCompiled(string source)
    {
 return _htmlRegex.Replace(source, string.Empty);
    }

    /// <summary>
    /// Remove HTML tags from string using char array.
    /// </summary>
    public static string StripTagsCharArray(string source)
    {
 char[] array = new char[source.Length];
 int arrayIndex = 0;
 bool inside = false;

 for (int i = 0; i < source.Length; i++)
 {
     char let = source[i];
     if (let == '<')
     {
  inside = true;
  continue;
     }
     if (let == '>')
     {
  inside = false;
  continue;
     }
     if (!inside)
     {
  array[arrayIndex] = let;
  arrayIndex++;
     }
 }
 return new string(array, 0, arrayIndex);
    }
}

What differ *.stp and *.wsp Windows Sharepoint Services files?

"A .stp (site template) file contains resources and a manifest file
relevant to an individual site template, and is limited in that it
only contains a site itself with lists, etc.  SPS 2003 and WSS 2.0
used .stp files, and they can still be used in MOSS 2007 and WSS 3.0.
They are convenient, in large part because a relatively inexperienced
user can save a site to template through the UI, and create new sites
from that template with no knowledge of the .stp file's contents, etc.


A .wsp (solution) file similarly contains resources and a manifest
file, but is more broadly used for extending MOSS 2007 and WSS 3.0
(not applicable to SPS 2003 or WSS 2.0), and is generally used for
deploying Features, which can consist of site definitions, lists, web
parts, custom actions, fields, etc., etc.  It is much more extensible
than the .stp framework, though it is also therefore more complicated
to use.


Errors while installing and configuring Sharepoint 2010


clip_image002
clip_image004
The Problems!
When installing SharePoint 2010 on Windows 7, even if you install all of its prerequisites that it says to install, you get one of these two errors:
An exception of type System.IO.FileNotFoundException was thrown.  Additional exception information: Could not load file or assembly ‘Microsoft.IdentityModel, Version 3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ or one of its dependencies.  The system cannot find the file specified.
-OR-
An exception oftype Microsoft.SharePoint.Upgrade.SPUpgradeException was thrown. Additional exception information: Failed to call GetTypes on assembly Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Could not load file or assembly ‘System.Web.DataVisualition, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find thefile specified.
-OR-
Failed to create the configuration database.
An exception of the type Microsoft.SharePoint.SPException was thrown.  Additional exception information: User cannot be found
(See both possible solutions below)
Below are the steps that I took to get these errors.
Installed SQL Server 2008 R2,  Installed SharePoint 2010 (with its prerequisites first).
Went to Start,  SharePoint 2010 Central Administraton
clip_image006
clip_image008
Clicked Yes
clip_image010
Clicked Next
clip_image012
WARNING: you are installing on windows vista or windows 7, which are unsupported configurations intended for use on developer workstations only.  This configuration should not be used as a production environment, or host any user content.
Clicked OK
clip_image014
Clicked Yes
You might get one of the errors below:
clip_image016
An exception of type System.IO.FileNotFoundException was thrown.  Additional exception information: Could not load file or assembly ‘Microsoft.IdentityModel, Version 3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ or one of its dependencies.  The system cannot find the file specified.
Click Finish.
The problem is that the Windows Identity Foundation pack was not installed.  This can be fixed here: http://www.microsoft.com/downloads/details.aspx?FamilyID=eb9c345f-e830-40b8-a5fe-ae7a864c4d76&displaylang=en#filelist
-OR-
clip_image018
An exception oftype Microsoft.SharePoint.Upgrade.SPUpgradeException was thrown. Additional exception information: Failed to call GetTypes on assembly Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Could not load file or assembly ‘System.Web.DataVisualition, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find thefile specified.
Click Finish.
The problem is that the Chart Controls cannot be found, you can download them here: http://go.microsoft.com/fwlink/?LinkID=122517
-OR-
clip_image020
Failed to create the configuration database.An exception of the type Microsoft.SharePoint.SPException was thrown.  Additional exception information: User cannot be found
Alright, this one is rather funny.  You can get this message if you are working from home, not connected to the network via VPN.  That was my case.  The user just cannot be found that is part of the domain for creating the SQL Server connection.
SUCCESS!!!
clip_image002[1]
That all worked for me, hope it works for you!

Type of events for document library.


Event Description
Cancel Check Out Changes made to a checked-out document are undone.
Check In A document is checked in to the library.
Check Out A document is checked out from the library.
Copy A document in the library is copied.
Delete A document is deleted from the library.
Insert A new document is saved to the library.
Move or Rename A document is moved or renamed.
Update An existing document or the value of a custom column in the library is edited.

Event Handler to prevent deletion of document from document library

  1. Start Microsoft Visual Studio 2010.
  2. On the File menu, point to New, and then click Project.



  3. In Project Types, under Visual Basic or C#, select Event Receiver.
  4. Type <Name for your project > as the project name. Click OK.
  5. In the SharePoint Customization Wizard, choose Deploy as a farm solution. Click Next.
  6. In the Choose Event Receiver Settings dialog, select List Item Events in the What type of event receiver do you want? choose from drop down dropdown.

  7. In the What item should be the event source? choose from dropdown, choose Tasks.
  8. Choose the An item is being deleted option in the Handle the following events list. Click Finish.
  9. In the EventReceiver1 file that is created, insert the following code in the ItemDeleting method.




using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace EventHandler
{
    class AnnouncementDeleteRevert: SPItemEventReceiver
    {
        public override void ItemDeleting(SPItemEventProperties properties)
        {
            string errorMessageToDisplay= ("Announcements can not be deleted from this list");
            properties.ErrorMessage = HandledMessage;
            properties.Cancel = true;


//or


properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Deleting items from " + properties.RelativeWebUrl + " is not supported.";
        }
    }
}

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...