Pages

Tuesday, January 27, 2015

How to redirect from one page to another in SharePoint Sandbox solutions (especially when they are deployed to SharePoint Online)



How to redirect from one page to another in SharePoint Sandbox solutions (especially when they are deployed to SharePoint Online)?



Answer -


There are lots of ways to achieve this but the following one works almost everywhere for the sandbox solutions.

On a button click event (or accordingly) of your ".cs" file, just add following code:


string pageURL = "www.yourpageurl.com";
var jscript = "<script type='text/javascript'
language='javascript'>window.location='"
+ pageURL + "';</script>";
var literal = new Literal();
literal.Text = jscript;
this.Controls.Add(literal);


The above code will add "Literal" control to page with the specified URL and the page will be redirected to the URL specified.

What is Literal Control?

- The Literal Control is similar to the Label Control as they both are used to display static text on a web page.
- The Literal Control is not inherited from WebControl namespace.
- The Literal Control doesn't provide substantial functionality but Literal text is programmable.
- It doesn't add any HTML elements to the web page. This control makes it possible to add HTML code directly in the code designer window without switching to design view and clicking the HTML button to edit the HTML.
- We cannot apply a style to a literal control.
- Unlike Label control, there is no property like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. for Literal control.

That makes it more powerful, we can even put a pure HTML contents into it.

When to use Literal Control?
- Literal control is one of the rarely used controls but it is very useful.
Literal control is light weight control.
- The Literal Control is useful when we want to add text to the output of the page dynamically (from the server).
- With that we can even programmatically manipulate the Literal text from the code behind.

In short we can say:

The Literal control is used to display text; that is, it renders static text on a Web page without adding additional HTML tags. It passes content directly to the client browser unless we use the Mode property to encode the content.
 

Read More »

Thursday, January 22, 2015

Change 'Title' Column Display Name Using List Definition In SharePoint

Question: How to change "Title" column display name in default view of a list when creating list by list definition using Visual Studio in SharePoint?

Answer: In Schema.xml file of your list definition project, search for "Fields" tag (i.e. <Fields>) and just before the closing tag of this "Fields" tag (i.e. </Fields> ), put below line of code (also see attached image):

<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="LinkTitle" DisplayName="First Name" />

In the above line of code:
ID = ID of your "Title" field
Type = Same as of your "Title" field i.e "Text"
Name = LinkTitle (it will refer to the "Title" text in default view)
DisplayName = The name you want to display in your default view instead of "Title"

Hope this helps!



Read More »

Wednesday, January 7, 2015

Cannot Connect To The SharePoint Site

Cannot Connect To The SharePoint Site

While creating a SharePoint solution in Visual Studio, if you get an error shown in a screenshot below when you validate your SharePoint site URL, just provide user with a "DB_Owner" access to the "WSS_Content", "WSS_Logging" and "SharePoint_Config" database. This will resolve the issue.




Read More »