• About Ken
  • Ken’s CV

All About SharePoint

~ Liedong(Ken) Zheng, Independent SharePoint Consultant

All About SharePoint

Category Archives: VS2008

ScriptManager.RegisterStartupScript and the RadAjaxPanel

20 Thursday Jan 2011

Posted by ken zheng in AJAX, VS2008

≈ Leave a comment

Tags

RadAjaxPanel

Most time you need to call a JavaScript function from code behind like exporting a dataset to excel by clicking button.

Response.Write("<script language='javascript'> window.open('http://website/folder/newdocument.pdf'); </script>")

or this (assuming a Literal control called ltlOpenPdf):

ltlOpenPdf.Text = "<script language=""javascript"">window.open('http://website/folder/newdocument.pdf');</script>"

However, the Response.Write is forbidden in Ajax and produces an error, while the Literal apparently did nothing at all.

After a few try, I found below code works well in RadAjaxPanel.

JS in html page

function openExportWindow() {
            window.open('ExportForm.aspx');
        }

Code in your button click
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "Export", "openExportWindow()", true);

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Advertisements

Setup project error: Unable to update the dependencies of the project

05 Friday Nov 2010

Posted by ken zheng in VS2008, vs2010

≈ Leave a comment

Tags

Setup Projects

I have consistently used this method to get around this bug instead of rebuilding my setup projects. This applies to both merge module projects AND setup projects. Manually remove the data in the Hierarchy and Files section of the project files.

1. Open .VDPROJ file

2. Find the "Hierarchy" section. Delete everything so the section looks like this:
    "Hierarchy"
    {
    }

3. Find the "File" section. Delete everything so the section looks like this:
        "File"
        {
        }

4. Reload the project

5. Rebuild the project.

6. You may need to re-add project outputs if missing something

Connect TO TFS 2010 From VS 2008

15 Friday Oct 2010

Posted by ken zheng in TFS, VS2008

≈ Leave a comment

Tags

TFS, VS2008

First, you need to download

Microsoft Visual Studio 2008 Service Pack 1 , Team Explorer 2008 and

Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010

Once you install everything, you can try adding Team Foundation Server 2010 as destination, but you will be greeted with error "TF31002: Unable to connect to this Team Foundation Server …". Reason behind this is that old Team Explorer 2008 does not know anything about collections.

Solution would be to add it as full path (e.g "http://server:8080/tfs/collection&quot;). I could not do it because every time I entered full path, I also got error "TF30335: The server name cannot contain characters ‘/’ or ‘:’ …". Since official way would not work it was time to come up with alternative.

In order to add TFS 2010 server, you will need to exit Visual Studio 2008 and go into Registry editor. Find key "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers" and at this location just add string value. Name of this value will be what Team Explorer 2008 will use for display. It’s value is full address of your server. It should be something like http://server:8080/tfs/collection.

Now you can go into Visual Studio 2008 and Team Explorer will have new entry. As you work with it, you will notice that not everything is "bump-free" (e.g. tasks). However, source control it self will work perfectly and that was enough for me.

How to load an icon from an embedded resource in C#

18 Thursday Feb 2010

Posted by ken zheng in VS2008

≈ 5 Comments

Tags

C#, ICON

Add the file (or icon) to the project, I like to create a folder for all my resource files.

1. (optional) Right click on the project and selected “Add” and then “New Folder”.
2. (optional) Rename new “NewFolder” to “Resources”.
3. Right click on the project (or “Resources” folder) and selected “Add” and then “Add Existing Item”.
4. Find the file (or icon).
5. Right click on the newly added file and select “Properties”
6. Set the “Build Action” property to “Embedded Resource”

Now when you compile the executable the file (or icon) will be embedded.

To use the embedded file use the following code (I have written it like this to illustrate the different steps, clearly you can condense the code into fewer lines)

System.Drawing.Icon icnTask;
            System.IO.Stream st;
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            st = a.GetManifestResourceStream("{{NameSpace}}.Resources.TaskIcon.ico");
            icnTask = new System.Drawing.Icon(st); 

Unable to see default Silverlight control in Toolbox

02 Wednesday Dec 2009

Posted by ken zheng in Silverlight, VS2008, vs2010

≈ Leave a comment

Tags

Silverlight

If you can’t see default Silverlight control in Toolbox, run “devenv /setup” or “/reestsettings” in Run or “Visual Studio 2008 Command Prompt”

BreakRoleInheritance(false) and AllowUnsafeUpdates

02 Tuesday Jun 2009

Posted by ken zheng in Sharepoint, VS2008

≈ 1 Comment

Tags

BreakRoleInheritance, SharePoint Security

. I’ve used the method for this previously in the solution,BreakRoleInheritance(false), so that no inherited roles are copied, but then this was done on a POST request and now it should do almost the same during a GET request, that is when the user navigates to the page.

All this is done under elevated privileges and looks something like this

SPSecurity.RunWithElevatedPrivileges(delegate() {
  using (SPSite site = new SPSite(url)) {
    using (SPWeb web = site.OpenWeb(url.Replace(site.Url, string.Empty))) {
      web.AllowUnsafeUpdates = true;
      Guid guid = web.Lists.Add(name, string.Empty, SPListTemplateType.DocumentLibrary);
      SPList list = web.Lists[guid];
      ...
      list.BreakRoleInheritance(false);
      ...
      list.Update();
    }
  }
});

This gives me the following error when running during a GET request.

“Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb.”

If I rewrite the code and change the BreakRoleInheritance(false) to BreakRoleInheritance(true) and set the AllowUnsafeUpdates to true once again it works fine and I have to manually get rid of all the roles.

Why is it so?

If you step through the code in the working sample you will see that after the BreakRoleInheritance(true) line the AllowUnsafeUpdates property of the SPWeb object has changed to false. The AllowUnsafeUpdates property will reset to false whenever any ISecurable object changes their role definitions, and in the BreakRoleInheritance method you have a call to an internal function that invalidates the SPWeb object which resets the AllowUnsafeUpdate property.

The exception is then thrown after breaking the role inheritance and when the method tries to remove the roles from the list. I initially thought that it was the other way around and therefore was a bit confused.

So the correct way is this:

SPSecurity.RunWithElevatedPrivileges(delegate() {
  using (SPSite site = new SPSite(url)) {
    using (SPWeb web = site.OpenWeb(url.Replace(site.Url, string.Empty))) {
      web.AllowUnsafeUpdates = true;
      Guid guid = web.Lists.Add(name, string.Empty, SPListTemplateType.DocumentLibrary);
      SPList list = web.Lists[guid];
      ...
      docLib.BreakRoleInheritance(true); //Exception throw here when the parameters is "false"
      web.AllowUnsafeUpdates = true;
      SPRoleAssignmentCollection roleAssigns = docLib.RoleAssignments;
      for (int i = roleAssigns.Count-1; i >= 0; i--)
     {
        roleAssigns.Remove(i);
      }
      list.Update();
    }
  }
}};

Reference:
http://www.wictorwilen.se/Post/BreakRoleInheritance-and-AllowUnsafeUpdates.aspx
http://www.delphi-ts.com/blogs/lozzi/2008/10/31/TheSecurityValidationForThisPageIsInvalid.aspx

ADO DOTNET Entity Data Model

24 Tuesday Mar 2009

Posted by ken zheng in .Net, VS2008

≈ Leave a comment

I am using VS 2008 Sp1 (not beta), when I want to create entity model, the entity model wizard closes with no error, when I choose from Database.

Install

EFB3setupx86 and EFToolsSetupX86, then

1) Open the “Visual Studio 2008 Command Prompt” (with administrator privileges if Vista)
2) devenv /resetskippkgs
3) Close Visual Studio
4) devenv /setup
5) Run Visual Studio

using C# to Replace special characters in XML

05 Thursday Mar 2009

Posted by ken zheng in VS2008

≈ Leave a comment

We can use the SecurityElement.Escape method to replace the invalid XML characters in a string with their valid XML equivalent [1].

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)

I have used the HttpUtility classes UrlEncode and UrlDecode methods to handle cross-site scripting attacks and this also helped me to get rid of the XmlException – “Data at the root level is invalid”.

tagText = SecurityElement.Escape(tagText);

http://msdn.microsoft.com/en-us/library/system.security.securityelement.escape(VS.80).aspx

the dependencies for the object cannot be determined

22 Monday Dec 2008

Posted by ken zheng in VS2008

≈ Leave a comment

The issue has very little support out there, so I wanted to post a few fixes I read about, and their result. I’ll post what fixed it for me, but I’m still searching for the all-encompassing solution. Maybe some of the fails below could fix your issue… Please post if you have ideas:

* Tried: Removing and re-adding setup projects: Result: fail
* Tried: Removing my database project and restarting VS: Result: fail
* Tried: Many, MANY, cleans and rebuilds of my solution: Result: fail
* Tried: Reinstall of VS Service Pack 1: Result: No immediate effect
* Tried: Remove and re-add of all project outputs and custom actions: Result: fail
* Tried: Opened the setup projects .vdproj file via Notepad, and removed references to offending project. Re-added my project outputs as usual using File Editor: Result: SUCCESS!

Get FileUpload Control Work In UpdatePanel

28 Tuesday Oct 2008

Posted by ken zheng in VS2008

≈ 1 Comment

Tags

FileUpload Control, UpdatePanel

According to Microsoft the FileUpload control is not compatible with an AJAX UpdatePanel. But you use a PostBackTrigger can be added to the submit button of the form like this:

In code:
PostBackTrigger trigger = new PostBackTrigger();
trigger.ControlID = SubmitButton.ID;
updatepanel.Triggers.Add(trigger);

← Older posts

Pages

  • About Ken
  • Ken’s CV

Blog Stats

  • 1,635,085 hits

.Net 3.5 5566 AJAX BCS BDC C# Calendar Content Type CSS Custom Page Document ID Fast Search favicon Feature IIS InfoPath infopath form JavaScipt JavaScript jQuery LINQ Listview Managed Property Master Page MCP MCPD migration MOQ MySite Page Layout PowerShell Proxy Search Search Scope SharePoiint 2010 SharePoiint 2010; Search SharePoin Sharepoint Sharepoint 2007 SharePoint2007 Sharepoint 2010 Sharepoint Search Silverlight Site Collection Site Definition Site Master Page site templates SPDisposeCheck SPD workflow SPSiteDataQuery SPUser SQL SSP stored procedure STSADM survey Tab TechEd Tech ED TSQL User Profile User Profiles Synchronization Service;SharePoint 2010 vs 2008 vs 2010 vs2010 WCF web.config webpart Web Part Web Service windbg workflow XML XSL XSLT

Archives

  • March 2016
  • April 2014
  • March 2014
  • February 2014
  • December 2013
  • October 2013
  • September 2013
  • March 2013
  • February 2013
  • August 2012
  • June 2012
  • May 2012
  • April 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008

Twitter Updates

  • @telstra @outage @3125 internet cable still not working since 8:30 am 6 months ago
  • @Telstra is internet cable service still down in Burwood Vic 3125? Have been issue for a day! 6 months ago
  • Anyone uses @Nintex Workflow for SharePoint online has email issue? all our external email actions are hanging since yesterday. 9 months ago
  • @Nintex Hi, is your Workflow External Email service is down? Since yesterday afternoon, no email being sent out usi… twitter.com/i/web/status/9… 9 months ago
  • @Nintex just wonder if there is any SharePoint online workflow server issue right now? All workflows are not reachable 1 year ago
Locations of visitors to this page

Blogroll

  • E-books Library
  • My Linkedin
  • SharePoint Community
  • SharePoint Developer Center
  • Silverlight Show
February 2019
M T W T F S S
« Mar    
 123
45678910
11121314151617
18192021222324
25262728  
Advertisements

Create a free website or blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy