Friday, June 25, 2010

Add PDF Icon to SharePoint Library

Quite obviously, we come across many occassions where PDF files are uploaded to SharePoint 2007 Libraries or Lists.

While we can easily see the images of our regular Word, Excel, PowerPoint documents, however the PDF documents look empty without the trademarked image.

Well, no problem, who says we can't have it. It is fairly simple, so let us see how:
  • Get the appropriate Adobe PDF icon image (preferrably a gif) from here 
  • Save that image confirming with SharePoint images standard such as icopdf.gif. Place the image where Office document icons exist by-default. Check out this 12 Hive path of your MOSS 2007 installation:
    Drive\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Images
  • Now that we have successfully placed the image, we need to inform SharePoint about our modification. For doing this, we need to add an entry to the DocIcon.xml file which sits in the Drive\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Xml path
  • Open the docicon.xml with any editor such as Visual Studio or even Notepad. Under ByExtension section, add a key/value pair as given below:
    Mapping Key="pdf" value="icopdf.gif"
    Note
    : Take a backup copy of the DocIcon.xml prior to the changes (to be on the safe side). Also, the XML start-end tags are removed as the post wouldnt allow it easily. Kindly take care in your case.
  • Save changes to Docicon.xml file. Perform an IISRESET command to finalize the same.
Refresh & check the same list or library page to notice the changes take effect.
Briefly, what this does has done is, if SharePoint sees any file (new/old) with an extension .pdf, it would display the PDF icon against the file as it does for Office documents.

Hope y'all find this information helpful. Cyaaa..and..stay tuned!!

Saturday, June 19, 2010

SharePoint Timer Job stuck at Deploying

Dealing with SharePoint solution packages and solution deployment stuck at "Deploying" status!!

Well don’t panic, here is just what the doctor ordered:

  1. Check the Timer Job Status for the solution deployment in Central Administration. There could be entries with “Failed” as the job status.
  2. Lets try to set things right by running stsadm -o execadmsvcjobs command.
    Note that in a farm environment, you need to run the above command on all the servers.
  3. As a next step, try restarting the OWSTIMER Service on all boxes in the farm.
  4. If the above steps do not help the solution deployment. You may try retracting the solution using Retract solution command or through the Central Admin's Solution Management.
    stsadm.exe -o retractsolution -name
    For your knowledge, retracting a solution creates another “deployment job”.

    Now if retracting the solution does not work, do not try to Force Delete the solution as that would throw an exception, "The solution cannot be removed when job is scheduled or running"
  5. Get a list of all the pending & active deployments on your MOSS Farm using
    stsadm -o enumdeployments command.
    Make a note of the GUID of the various solutions on the command window as this would be required in next step.
  6. As a last nail in the coffin, we now need to simply cancel the solution deployment by passing the GUID of the solution as shown below
    stsadm -o canceldeployment -id "job id string here"
After performing the above steps, you would be able to either put the SharePoint Timer Job into completion or atleast remove the solution package being stuck in deployment.

If the problem still persists (esp. in the MOSS 2007 Farm environment), you might need to remove/detach a defective WFE from the farm and then retry deployment.


I have tried to put together the steps which have worked for me, hope this post helps you all too.

Tuesday, June 8, 2010

Dotnet Cleanup Tool

This is not a promotion but sharing my learning about an awesome tool for fixing old..stuck-up..incomplete..DotNet framework installations.

I personally learnt about it while coming across one of the blogs.

Do try it to remove the .NET Framework 1.0, 1.1, 2.0, 3.0 and 3.5 This would even help you if you want to go ahead with a clean install of .Net 4.0 

Try .Net Cleanup Tool

HTH.

Monday, June 7, 2010

SharePoint DateTime Format Conversions

SharePoint 2007 uses ISO8601 DateTime format internally. It understands either of 2 possible notations for DateTime:

YYYY-MM-DDThh:mmTZor
YYYY-MM-DDThh:mm:ssTZD

where,
  • understandably YYYY being 4-digit year, MM for 2-digit month number, DD for day of month
  • T stands for start of time.
  • Following that denotes the time which could be "hh:mm" (hours-mins) or "hh:mm:ss" (hours-mins-seconds)
  • Z indicates the Coordinated Universal Time (UTC)
On many occassions during MOSS 2007 development, we are required to convert from DateTime to ISO8601 DateTime or vice-versa. So, I decided to post on how this could be achieved.

Convert from DateTime to ISO8601 DateTime (C#):

DateTime date = DateTime.Now;
string isoDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(date);

When you are trying to insert or modify some DateTime fields to or from a SPListItem, you could use the code given above to format values into ISO 8601.
You can build the CAML query for the SPQuery object as shown below:
Example:
Note: Don't forget to add reference of Microsoft.SharePoint.Utilities in your class file before building your project.

Convert from ISO8601 to DateTime (C#):
DateTime date = DateTime.Parse("2010-06-15 00:00:00");
string sysDate = date.ToString("MM/dd/yyyy");

Note: In above example, the ISO DateTime string is converted to DateTime equivalent using DateTime.Parse method.

Also, incase you want to change the Site Collection date format:
  1. Go to "Site Settings" & navigate to "Modify All Site Settings"
  2. Click on Regional Settings under Site Administration
  3. Change the time zone. Save the changes.
This brings us to the end of this lengthy post. Hope it helps you SharePoint folks, goodbye for now.

Saturday, June 5, 2010

Resolve MachineToApplication error in web.config

Sometime, when you are trying move your SharePoint application from your Staging to Production environment, did you come across this ugly error:

Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

I am sure, this is enough to spoil the party just when you are expecting your SharePoint website to be up-n-running in the live environment. Now the question comes, "How do we fix this darn thing?"

Well for that, you could try the below suggestions. If you read the error message carefully, it has 2 hints already in it.

Hint #1: virtual directory not being configured as an application in IIS

Resolution: Make sure you have correctly configured your web application in IIS Manager. If it is a simple folder in wwwroot directory, you should "convert" it into web application.
  1. Open IIS manager
  2. Find your folder, right-click -"Properties"->"Create" button
  3. Recycle the application pool
Hint #2: c:\inetpub\wwwroot\webservices\...\web.config line XX where XX stands for line number in web configuration file

Resolution: If you do a find for line XX in your web.config, you are sure to reach this line,
 
For fixing this, comment this line in this fashion and then save the web.config:

Try accessing your site after the above modifications, it should work fine now.
That's all folks!! (for now :D), please let me know if this helped.

Friday, June 4, 2010

.Net 4.0 Framework Evolution

As you must be aware that Microsoft has unveiled its latest Dotnet Framework 4.0, I just thought I should add some information and provide download links for .Net framework 4.0.

4.0 is a superset of older versions of framework but it is independent of 3.5 or any other older frameworks. It is a standalone package.It is independent due to its brand new CLR

The framework is constantly reviewed by MS. If you see the evolution of the framework, the 2.0, 3.0, 3.5 had been on the same CLR but it was much different from previous 1.1 Framework. The versions which followed 1.1 had vast modifications. And, now 4.0 has comeout as a new offspring as shown below:

There are various products such as Visual Studio 2010, SPS2010, BizTalk 2010, etc.. which are already based on this new 4.0 framework.So fire up your engines and try your hands by downloading the latest .Net 4.0 Framework Offline Setup package from this link download

Tuesday, June 1, 2010

Find the IP Address of the SharePoint 2007 User

Suppose you have a SharePoint website that is being accessed by a lot of users everyday (~1K users daily).

Now for some reason or the other you want to capture the client IP address of the end user accessing your MOSS web application.

Purposes could be like:

  • Reporting/Logging user IP address
  • Security purposes
  • Filtering content based on the client IP address
  • Getting the location of the user based on the client IP address
  • so on..
You could simply use HttpContext.Current.Request.UserHostAddress to get the IP address of a user.

This could be easily used in both ASP.Net applications as well as SharePoint development projects.

LinkWithin

Related Posts with Thumbnails