Posted by ken zheng on July 28, 2009
You know you can’t add a webpart zone into Master page directly, but there is tricky you can do it.
Just add
<asp:ContentPlaceHolder id="WeatherPart" runat="server"></asp:ContentPlaceHolder>
In the pagelayouts, set a control with the same id-name and place your webpartzone inside. You have to do this for every pagelayout that needs a header image in the masterpage. For each page though, there has to be added a image webpart, or whatever webpart you like. So be aware of this, if you use a webpartzone in your masterpage.
<asp:Content ContentPlaceHolderId="WeatherPart" runat="server">
<div>
<WebPartPages:WebPartZone runat="server" Title="WeatherPart" ID="WeatherPart"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</div>
</asp:Content>
Posted in Sharepoint | Tagged: Sharepoint 2007, webpart | 1 Comment »
Posted by ken zheng on July 23, 2009
You may experience this problem when you try to run an existing SilverLight project.
I only know the quick and dirty solution to this problem. (at least, it worked for my app)
You’ll have to open the .xap file with an archive program like winara. Edit the AppManifest.xaml file, and change the version number into the current number (something like 2.0.30825.0). And your program should work.
Posted in Silverlight | Tagged: Silverlight | Leave a Comment »
Posted by ken zheng on July 23, 2009
Just found this easy solution to hide the left navigation panel in sharepoint
The left navigation bar makes the page looks very “SharePoint”. And, some valuable space is wasted under it. If you don’t want to customize the Master page (or want to keep the left nav panel in the rest of the site), you can just hide it on the home page. Insert a Content Editor webpart, and edit the source by clicking the “Source Editor…” button, and enter this:
.ms-navframe{ display:none; }
That’s right, this is just to override the default style for that section.
Posted in Sharepoint | Leave a Comment »
Posted by ken zheng on July 23, 2009
By using Scott Price’s code, I add a query to the CAML so it will only display annoucment which not expired.
<script type="text/javascript" src="/Development Library/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/Development Library/jquery.newsticker.js"></script>
<script type="text/javascript" src="/Development Library/DateUtilities.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
soapEnv += "<listName>Announcements</listName>";
soapEnv += "<query><Query><Where><Geq><FieldRef Name='Expires' /><Value Type='DateTime'><Today/></Value></Geq></Where></Query></query>";
soapEnv += "<viewFields><ViewFields><FieldRef Name='Title'/><FieldRef Name='Created'/><FieldRef Name='ID'/></ViewFields></viewFields>"; //<RowLimit>1</RowLimit>
soapEnv += "</GetListItems></soapenv:Body></soapenv:Envelope>";
$.ajax({
url: "../_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
});
function processResult(xData, status) {
var newnews = $("<ul>").attr("class", "newsticker");
var rows;
if (xData.responseXML.getElementsByTagName("z:row").length==0)
{
var url = "/test/Lists/Announcements/";
var liHtml = "<li class='newscontent'> <b> No Latest News <br><br><a href='" + url + "'>Read All"+"</a></b></li>";
newnews.append(liHtml);
}
else
{
rows = xData.responseXML.getElementsByTagName("z:row");
jQuery(rows).each(function() {
var createdDate= $(this).attr("ows_Created").split(" ");
var url = "/test/Lists/Announcements/DispForm.aspx?ID=" + $(this).attr("ows_ID");
createdDate = parseDate(createdDate[0]);
var liHtml = "<li class='newscontent'>" + formatDate(createdDate ,'dd MMM yy')+ " - <b>" + $(this).attr("ows_Title")+ "<br><br><a href='" + url + "'>Read Details"+"</a></b></li>";
newnews.append(liHtml);
});
}
newnews.appendTo("#tasksUL").newsTicker();
}
</script>
<style type="text/css">
.newsticker {
list-style-type: none;
height:50px;
color:#336699;
margin-top: 10;
}
.newscontent{
list-style-type: none;
margin-left: 0;
display: inline;
}
.news{
background: url(/_layouts/1033/IMAGES/SIMCENTRAL/link_m.gif) no-repeat scroll center top;
width:240px;
}
.marktop {
background:transparent url(/_layouts/1033/IMAGES/SIMCENTRAL/link_t.gif) no-repeat scroll center top;
height:11px;
padding:0;
width:240px;
}
.markbottom {
background:transparent url(/_layouts/1033/IMAGES/SIMCENTRAL/link_b.gif) no-repeat scroll center top;
height:11px;
margin-left:0;
padding:0;
width:240px;
}
.markcenter {
height:auto;
margin-top:10;
padding:0;
width:211px;
}
</style>
<div class="markcenter">
<div class="marktop"/>
<div class="news">
<br>
<b> Noticeboard</b>
<div id="tasksUL"
</div>
</div>
<div class="markbottom"/>
</div>
Posted in Uncategorized | Tagged: jQuery, SharePoint Web Service | 1 Comment »
Posted by ken zheng on July 22, 2009
You have sometimes this error while developping a SharePoint application :
Server Error in ‘/’ Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Even if you have activated the possibility to see errors and trace in SharePoint (Web application web.config –> callstack=”true”, customerror=”off”, debug=”true”) you won’t have a precise indication of what ressource is missing.
So just right click your page and choose “view source”.
Bingo! :
Posted in Sharepoint | Leave a Comment »
Posted by ken zheng on July 21, 2009
You see receive the “Thread was being aborted excpetion ” thrown by Response.Redirect(“Login.aspx”). There is nothing wrong with your code, and it is designed on that way.
For a workaround you can use an overload to
Response.Redirect that will pass false to the endresponse parameter to
suppress the internal call to Response.End (e.g.
Response.Redirect(“Login.aspx”, false);).
Posted in .Net | Tagged: ASP .NET | Leave a Comment »
Posted by ken zheng on July 15, 2009
Very often you need SPUser but only have Full Name of the user. By using AD Search you can get user login name.
using System.DirectoryServices;
const string ADPATH = "LDAP://myLDAPserver,validUserforAD";
const string USERNAME = "myDomain\\myUserName";
const string PASSWORD = "myPassword";
const string DOMAIN = "myDomain\\";
public static DirectoryEntry GetDirectoryObject()
{
DirectoryEntry directoryObject = new DirectoryEntry(ADPATH, USERNAME, PASSWORD, AuthenticationTypes.Secure);
return directoryObject;
}
public string GetUserNameByCompleteName(string completeName)
{
DirectoryEntry adObject = GetDirectoryObject();
//filter based on complete name
DirectorySearcher searcher = new DirectorySearcher(adObject);
searcher.Filter = "displayname=" + completeName;
SearchResult result = searcher.FindOne();
DirectoryEntry userInfo = result.GetDirectoryEntry();
//getting user name
string userName = (string)userInfo.Properties["samaccountname"].Value ?? string.Empty;
userInfo.Close();
adObject.Close();
return DOMAIN + userName;
}
SPUser user = web.Site.RootWeb.SiteUsers[loginName]
Posted in Sharepoint | Tagged: SPUser | Leave a Comment »
Posted by ken zheng on July 14, 2009
SPSecurity exposes a method called “RunWithElevatedPrivileges” which gives you an option to elevate the privilege to the application pool identity under which your code is executing. Looks nice, eh?
But Wait a second!! You are not done yet. I wish it was that easy when it comes to impersonation. In order to get this method call to properly impersonate your application pool identity you need to do some more work. Basically, SPSite and SPWeb objects created outside do not have Full Control even when referenced inside the delegate (anonymous method), so you need to find out their GUID before impersonation is performed and re-create the context one more time. Finally,never forget to dispose your objects!
You basically need to create parentWeb again via creation of a new SPSite, SPWeb etc. within the RunWithElevatedPrivileges block.
//Don’t dispose the following two objects. Sharepoint will take care of their disposal when page is completely rendered.
SPWeb webInUserContext = SPContext.Current.Web;
SPSite SiteInUserContext = SPContext.Current.Site;
Guid webGuid = webInUserContext.ID;
Guid siteGuid = SiteInUserContext.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// get the site in impersonated context
using (SPSite site = new SPSite(siteGuid))
{
// get the web in the impersonated context
SPWeb web = site.OpenWeb(webGuid);
web.AllowUnsafeUpdates = true;
// Do your work here
web.Dispose();
}
});
Here is some references:
http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!2005.entry
http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!927entry
http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?List=f0e16a1a%2D6fa9%2D4130%2Dbcab%2Dbaeb97ccc4ff&ID=43
Posted in Sharepoint | Leave a Comment »
Posted by ken zheng on July 13, 2009
1. Click Start -> Run and type: regedit
2. Click Ok
3. Locate: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\ Eventlog\Application
4. Modify CustomSD to give all users read/write access to the Application event log by appending the string (A;;0×3;;;AU) to the CustomSD entry.
For example
O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0xf0007;;;SY)(A;;0×7;;;BA) (A;;0×7;;;SO)(A;;0×3;;;IU)(A;;0×3;;;SU)(A;;0×3;;;S-1-5-3)(A;;0×3;;;AU)
The completed blog is http://mossipqueen.wordpress.com/2008/08/04/cannot-open-log-for-source-you-may-not-have-write-access/
Posted in Uncategorized | Leave a Comment »