Wednesday, December 29, 2010

Anonymous user access CQWP

When trying to access Content Query Web Part with anonymous user, It failed to render. While it is working correctly with anonymous user.

I’ve found out that we can fix this issue by adding two fields to the CommonViewFields property of the CQWP:

DocumentIconImageUrl and OnClickForWebRendering, like this:


<property name="CommonViewFields" type="string">DocumentIconImageUrl, Text;OnClickForWebRendering,Text </property>

Other work around:

Create WebPart inherit the CQWP and add an extra column to the resulting table containing data:


public class AnonWorkingContentByQueryWebPart : ContentByQueryWebPart
{
protected override void OnInit(EventArgs e)
{
this.ProcessDataDelegate = ProcessItems;
}

protected virtual DataTable ProcessItems(DataTable data)
{
DataColumn column = new DataColumn("OnClickForWebRendering", typeof(string));
data.Columns.Add(column);

return data;
}
}

I prefer first solution

Webya give unauthorized error

When we added webya to our site it prompt with authentication. When we cancelled authentication page appear without any problem.

After investigation we found webya try to access /pages. To ignore this problem we added HTTPModule to escape this authetication. Sample Code as below:

public class BadRequestHandler : IHttpModule
{
///


/// Don't let the response be cached by the browser. Set up the status code
/// and return.
///

public void ProcessRequest(HttpApplication context)
{
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(DateTime.MinValue);
if (context.Request.Url.AbsolutePath.ToLower().EndsWith("/pages/"))
ParseStatusCode(context, 200);
}

///


/// Actually set up the status code at this point, and return.
///

protected void ParseStatusCode(HttpContext context, int statusCode)
{
context.Response.StatusCode = 200;
context.Response.End();
}

public bool IsReusable
{
get { return true; }
}

public void Dispose()
{
}

public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}

void context_BeginRequest(object sender, EventArgs e)
{
//System.Web.HttpContext.Current.Response.Write("handler started");
System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.MinValue);
if (System.Web.HttpContext.Current.Request.Url.AbsolutePath.ToLower().EndsWith ("/pages/"))
{
ParseStatusCode(System.Web.HttpContext.Current, 200);
}
}
}

Opening HTML Files in Sharepoint 2010

By default, Sharepoint 2010 is blocking the ability to open HTML, Flash, ...some types files directly from a document library. It download it instead of displaying it.

This can be changed in the browser file handling option. To change this option go to:

1. Central Admin\Application Management\Manage Web Applications.
2. Select General Settings for the specified web application
3. For Browser file handling, select permissive. The default is strict.

If we need to keep this option for security.
SharePoint 2010 put these types static in code, You need to create HTTPModule to remove attachment from its header. Example in code below:


public class FixHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}

public void Dispose()
{

}

void OnPreSendRequestHeaders(object sender, EventArgs e)
{
// modify the "Server" Http Header
if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".htm")
HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".html")
HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".swf"))
HttpContext.Current.Response.Headers.Remove("Content-Disposition");
}
}

Tuesday, December 28, 2010

Add Additional Column to SharePoint 2010 Programmatically

When worked in project I faced problem in adding additional lookup column to list programmatically and I didn't found any article to guide me of doing it. After investigation I found the solution.
Example I have Lookup 2 lists:

  1. Countries with 2 text columns Title as key and Code.
  2. Application have lookup with name CountryTitle

I want to add Code Column of Countries list as additional column of look CountryTitle. The Code below do this action:


string mainListName = "Countries"; //Name of Lookup List
string lookupListName = "Application"; //Name of Main List Needs to add additional field to lookup
string lookupColAdditionalFieldDisplayName = "CountryCode"; //Display name of additional field in main list
string pLookupKeyName = "CountryTitle"; //Name of parent lookup field in main List
string additionalLookupFieldName = "Code"; //Name of additional Field in lookup list
//Main List
SPList mainlst = w.Lists[lookupListName];

//Lookup List
SPList lookuplst = w.Lists[mainListName];

//Main List Fields
SPFieldCollection col = mainlst.Fields;

//Lookup Primary Key
SPFieldLookup spPrimaryField = ((SPFieldLookup)col[pLookupKeyName]);

//Create Additional Field its name in lookup Field1 with display name in list TestDisplayName
SPFieldLookup field = (SPFieldLookup)mainlst.Fields.CreateNewField(SPFieldType.Lookup.ToString(), lookupColAdditionalFieldDisplayName);
field.LookupList = spPrimaryField.LookupList;
field.LookupWebId = spPrimaryField.LookupWebId;
field.LookupField = additionalLookupFieldName;
field.PrimaryFieldId = spPrimaryField.Id.ToString();
field.ReadOnlyField = true;
field.AllowMultipleValues = spPrimaryField.AllowMultipleValues;
field.UnlimitedLengthInDocumentLibrary = spPrimaryField.UnlimitedLengthInDocumentLibrary;
field.Direction = spPrimaryField.Direction;
SPAddFieldOptions op = SPAddFieldOptions.Default;

//Add Additional Field to main list
mainlst.Fields.AddFieldAsXml(field.SchemaXml, true, op);

Thursday, June 3, 2010

"Upload Multiple Documents" option is missing in IE

if you found "Upload Multiple Documents" option is missing in IE do the following steps:

1) Browse to your website at http:///_layouts/settings.aspx; you will need to login by providing a service account name & password or your site collection administrator account & password.

2) Once you login, click on 'Site Actions' menu.

3) Then, click on 'Manage Site Content and Structure'.

4) Click on any document library you want to upload or add files into. If you do not see the 'Upload' menu from the dropdown main menu between the 'New' and 'Actions' menu then you have this bug as well showing up on your server. Don't give up yet, there is a solution. Keep going through these steps!

5) Click on 'New' and select 'Item'.

6) You should now see the Upload Document page; under the input browse field there should be a link for 'Upload Multiple Files...', if you do not see this you will need to install either Office 2003 or Office 2007. If you do see it, click on it.

7) Now, you should see the multiple upload page that allows you to select multiple files. If you try to select one or several and click on the OK button, nothing will happen. No need to worry! There is a work around. Just keep reading to the next step.

8) On the hierarchy navigation you will have links something like this:

WebSiteName > Folder1 > Folder2

9) Click on the "Document Library" folder name; in our case it was Folder1. Basically its the folder you ended up in in step #4.

10) Now, did you notice anyting in your menu change? Now you should be able to see the Upload menu option between the 'New' and 'Actions' menu that you could not see in step #4.

11) Click on the 'Upload' menu and select 'Upload Multiple Documents'

12) Now, you will be back at the Upload document page where you were in step #7

13) Select one file or many and then click OK. Now it works!!! You should get an IE popup asking you that your about to upload files to your site, Click OK.

Saturday, March 13, 2010

Moss 2007 Site Action -> Site Settings have disappeared

For some unknown reason for the admin user of our Moss site (and all other users who had full control permissions) the Site Action -> Site Settings menu option have disappeared from the home page. I can navigate to it by going to mysite/_layouts/settings.aspx but I can't change anything it says I do not have permissions.

IF the user logged IS the Site Collection administrator and still gets theses access denied messages, your Content Database seems to be locked. This happens during backups or when backups go wrong (get interrupted for example)
stsadm -o getsitelock -url http://server_name

if it is not showing as 'none', it is locked. fix command:
stsadm -o setsitelock -url http://server%5Fname -lock none

Thursday, March 11, 2010

How to change the Maximum File Upload Size

When a custom master page is applied, editing a list in Datasheet View causes IE to just hang. I found this script hich solved my problem:
<script type="text/javascript">

function GCComputeSizing(GCObject)
{
if (TestGCObject(GCObject))
{
var fBIDI=(document.documentElement.currentStyle.direction=="rtl");
var lGCWindowWidth=document.documentElement.scrollWidth;
var lGCWindowHeight=(document.documentElement.scrollHeight>document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.documentElement.scrollHeight;

var lGCObjectOffsetLeft=0;
var lGCObjectOffsetTop=0;
if (fBIDI)
{
lGCObjectOffsetLeft=-180;
lGCObjectOffsetTop=120;
}
else
{
lGCObjectOffsetLeft=32;
lGCObjectOffsetTop=-2;
}
var lGCObjectWalker=GCObject.parentElement;
while (lGCObjectWalker !=document.body)
{
lGCObjectOffsetLeft+=lGCObjectWalker.offsetLeft;
lGCObjectOffsetTop+=lGCObjectWalker.offsetTop;
lGCObjectWalker=lGCObjectWalker.offsetParent;
if (fBIDI)
if (lGCObjectWalker.offsetLeft > 0)
break;
}
lGCObjectOffsetLeft+=GCObject.parentElement.offsetLeft;
lGCObjectOffsetTop+=GCObject.parentElement.offsetTop;
glGCObjectHeight=lGCWindowHeight - lGCObjectOffsetTop;
if (glGCObjectHeight > lGCWindowHeight)
glGCObjectHeight=lGCWindowHeight
if (glGCObjectHeight < cGCMinimumHeight)f
glGCObjectHeight=cGCMinimumHeight;
if (fBIDI)
{
glGCObjectWidth=lGCWindowWidth+lGCObjectOffsetLeft;
}
else
glGCObjectWidth=lGCWindowWidth - lGCObjectOffsetLeft;
if (glGCObjectWidth > lGCWindowWidth)
glGCObjectWidth=lGCWindowWidth;
if (glGCObjectWidth < cGCMinimumWidth)
glGCObjectWidth=cGCMinimumWidth;
}
}

</script>
place it after core.js in your master page.

How to change the Maximum File Upload Size

By default SharePoint allows a maximum file size of 50MB that can be uploaded into any document library. This might be too much as you might not want users downloading 50MB files over your LAN/WAN. To change the maximum file size
1. Goto SharePoint Central Administration > Configure Virtual Server Settings from Virtual Server List Page.
2. Select your server
3. Goto Virtual Server General Settings (in Virtual Server Management)
4. Change the value of the Maximum Upload Size in MB's.

If you increase the file size limit, your site might occassionally time out for users while they are uploading files. To accomodate this increase the default time out property for IIS.

Tuesday, February 23, 2010

DiscussionBoard ListView in onet.xml

When tried to create site definition and added ListView for DiscussionForum. Link of added Item redirected to the default Web page for the site intead of open.
<View List="Discussion Forums"
WebPartZoneID="Left" BaseViewID="0" WebPartOrder="3" Type="HTML" RowLimit="5"
/>

After investigation I found error occur if the XML parser cannot find a matching content type ID.

Solution:
add the ContentTypeID attribute together with the content type value "0x012001" to the View element code of the discussion Web part in the Onet.xml file:
<View List="Discussion Forums" ContentTypeID="0x012001"
WebPartZoneID="Left" BaseViewID="0" WebPartOrder="3" Type="HTML" RowLimit="5"
/>