Wednesday, November 28, 2012

How to extract metadata or details of a DLL IN GAC using Powershell

Hi,
 Recently I came across an issue to fetch the details of the DLL in GAC Folder.
Detail are like, Name , Version Number and TimeStamp using powershell.

I searched a lot in google and blogs and also in MSDN but didnt found any fruitful result.
Finally after too much to working on this  I finally came up with a simple solution.

Here is the script:



set-variable -option constant -name out -value "dllInventory.csv"
"Name, Version, Time" | Out-File $out -Append



Foreach( $file in Get-ChildItem C:\windows\assembly  -Recurse -filter "*.dll" )
{
if ($file -match "(.*dll)$")
{

 #$temp =  $file.Name, $file.VersionInfo.FileVersion, $file.lastwritetime
     $file.Name + ", " + $file.VersionInfo.FileVersion + ", " + $file.lastwritetime | Out-File $out -append
}
else
{write-host "Not Found"}
}
}
Hope this is help !!

Friday, November 23, 2012

Iterate in Resource File and fetch value of the matching String

Hi Reader,

Recently I came across a requirement where I need to iterate in a resource file added in my ASP.NET Project and fetch the matching value of a specific string.
Exact requirement goes like this, I have to return a Token Key ( Value ) of a Domain Name ( String Name) in a resx file. If the URL contains the Domain Name which is added in resx file then respective Token Key is fetched.
So we need to loop in the resx file, look for the containing string and if it matches then returns the value.
Code goes like this :


ResourceManager resourceManager = new ResourceManager("Resources.SiteUrl", System.Reflection.Assembly.Load("App_GlobalResources"));
                        
                        ResourceSet resourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
                        foreach (DictionaryEntry entry in resourceSet)
                        {
                            object resourceKey = entry.Key;
                            object resource = entry.Value;
                            if (returnUrl.Contains(resourceKey.ToString()))
                            {
                                DomainName = resourceKey.ToString();
                                Token = resource.ToString();
                            }
                        }
                        if (DomainName != null)
                        {
                            if (returnUrl.Contains(DomainName))
                            {
                                returnUrl = string.Format("{0}/_layouts/Authenticate.aspx?{1}={2}", returnUrl, Token, authCookie);
                            }
                        }


In Above code , ResourceManager Object is created to that looks up resources contained in files with the specified root name in the given assembly. 
ResourceSet Stores all the resources localized for one particular culture, ignoring all other cultures, including any fallback rules.

DictonaryEntry will get the key value pair of each item in the resource file.

Hope this helps !!



Saturday, November 10, 2012

How to Remove Site Template from Custom Tab

Hi All,

I have created test site template with name MyTestTemplate and MyTestTemplate2. Since this site is used by many developers and designers.
Later I found that in the Solution Galllary does not have any such solution with name MyTestTemplate and MyTestTemplate2 but it was still showing in Custom TAB of Site Template.





After those templates were deleted in the Solutions Gallery, they were still listed in the Custom group of new site templates, and could still be used - maybe because they were still available in the Recycle Bin.
To hide them from the Create Site options, I restored them from the Recycle Bin, then chose Deactivate from each item's drop-down menu, and then deleted them again. That solved the problem.

Friday, November 9, 2012

HOW TO ADD A CALENDAR LIST VIEW WEB PART TO ONET.XML

Hi All,

My requirement was to add a calendar in a provisioned page so I found there is a way to set web part properties inside a CDATA section of the view. The Views are generated from the Microsoft.SharePoint.WebPartPages.ListViewWebPart.

I hope this code will help your requirements as well.


<View List="Lists/PluginCalendar" BaseViewID="2" Type="CALENDAR"
       Scope="Recursive" RecurrenceRowset="TRUE" WebPartZoneID="TopWebZone"
       WebPartOrder="0">
       <![CDATA[
         <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
             <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,
                       PublicKeyToken=71e9bce111e9429c</Assembly>
             <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart
                       </TypeName>
             <Title>Calendar of Events</Title>
             <FrameType>None</FrameType>
         </WebPart>
       ]]>
 </View>

Cannot recognize the XML namespace of this Web Part

Hi All,


When provisioning pages (e.g. default.aspx) using a feature, you can add default webparts using <AllUsersWebPart>
Keep in mind you have two types of webparts, v2 en v3. When provisioning v2: you should use the following syntax:
<AllUsersWebPart WebPartZoneID="FooterLeft" WebPartOrder="2">                
<![CDATA[                             
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">                  
...
</WebPart>                
]]>            
</AllUsersWebPart>
and with v3:
<AllUsersWebPart WebPartZoneID="FooterLeft" WebPartOrder="5">                
<![CDATA[                    
<webParts>                      
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">   ... 
</webPart>                    
</webParts>                
]]>            
</AllUsersWebPart>
Look at the difference in attributes of WebPart-tag AND the extra <webParts> tag in the v3-version. If you add <webParts> around the <webPart>-declaration in the v2-version, you could receive the error: Cannot recognize the XML namespace of this Web Part.