Q.
What are the differences between the two base classes and what are the inherit
benefits of using one over another? Ans. The difference is the
Microsoft.SharePoint.WebPartPages.WebPart base class is meant for backward
compatibility with previous versions of SharePoint. The benefit of using the
SharePoint WebPart base class is it supported:
Cross
page connections
Connections
between Web Parts that are outside of a Web Part zone
Client-side
connections (Web Part Page Services Component)
Data
caching infrastructure
ASP.NET
2.0 WebParts are generally considered better to use because SharePoint is built
upon the ASP.NET 2.0 web architecture. Inheriting from the ASP.NET 2.0 base
class offers you features that inherit to ASP.NET 2.0, such as embedding
resources as opposed to use ClassResources for deployment of said types.
Q.
What is the GAC? Ans.
The GAC stands for the global assembly cache. It is the machine wide code cache
which will give custom binaries place into the full trust code group for
SharePoint. Certain SharePoint assets, such as Feature Receivers need full trust
to run correctly, and therefore are put into the GAC. You should always try to
avoid deployment to the GAC as much as possible since it will possibly allow
development code to do more than it was intended to do.
Q.
What is strong naming (signing) a WebPart assembly file mean? Ans. Signing an
assembly with a strong name (a.k.a strong naming) uses a cryptographic key pair
that gives a unique identity to a component that is being built. This identity
can then be referred throughout the rest of the environment. In order to
install assemblies into the GAC, they must be strongly named. After signing,
the binary will have a public key token identifier which can be use to register
the component in various other places on the server.
Q.
What are safe controls, and what type of information, is placed in that element
in a SharePoint web.config file? Ans. When you deploy a WebPart to
SharePoint, you must first make it as a safe control to use within SharePoint
in the web.config file. Entries made in the safe controls element of SharePoint
are encountered by the SharePointHandler object and will be loaded in the
SharePoint environment properly, those not will not be loaded and will throw an
error.
In
the generic safe control entry (this is general, there could be more), there is
generally the Assembly name, the namespace, the public key token numeric, the
typename, and the safe declaration (whether it is safe or not). There are other
optional elements.
Q.
What is the CreateChildControls() method? How can you use it to do something
simple like displaying a Label control? Ans. The CreateChildControls method in
WebParts is used to notify the WebPart that there are children controls that
should be output for rendering. Basically, it will add any child ASP.NET
controls that are called instantiating each control with its relevant
properties set, wire any relevant event handlers to the control, etc. Then the
add method of the control class will add the control to the controls
collection. In the relevant WebPart render method, the EnsureChildControls
method can be called (or set to false if no child controls should be called) to
ensure that the CreateChildControls method is run. When using
CreateChildControls it implies that your WebPart contains a composition of
child controls.
In
order to create something like a label control in Create, you would create a
new label control using the new keyword, set the various properties of the
control like Visible=True and ForeColor = Color.Red, and then use
Controls.Add(myLabelControl) to add the control to the controls collection.
Then you can declare EnsureChildControls in the Render method of the WebPart.
Q.
What does the RenderContents method do in an ASP.NET 2.0 WebPart? Ans. The render
contents method will render the WebPart content to the writer, usually an
HtmlTextWriter since WebParts will output to an HTML stream. RenderContents is
used to tell how the controls that are going to be displayed in the WebPart
should be rendered on the page.
***
Side Question: I got asked what the difference between CreateChildControls and
the RenderContents method. The CreateChildControls method is used to add
controls to the WebPart, and the RenderContents method is used to tell the page
framework how to render the control into HTML to display on a page.
Q.
What is the WebPartManager sealed class? What is its purpose? Ans. The
WebPartManager sealed class is responsible for managing everything occurring on
a WebPart page, such as the WebParts (controls), events, and misc.
functionality that will occur in WebPartZones. For example, the WebPartManager
is responsible for the functionality that is provided when you are working with
moving a WebPart from WebPartZone to WebPartZone. It is known as the “the
central class of the Web Part Control Set.”
***
Side Question: I got asked how many WebPartManager controls should be on a
page. In order to have WebParts on a page there has to be just one
WebPartManager control to manage all the WebParts on the page.
Q.
What is a SPSite and SPWeb object, and what is the difference between each of
the objects? Ans.
The SPSite object represents a collection of sites (site collection [a top
level sites and all its subsites]). The SPWeb object represents an instance
SharePoint Web, and SPWeb object contains things like the actual content. A
SPSite object contains the various subsites and the information regarding them.
Q.
How would you go about getting a reference to a site? Ans. C#:
oSPSite
= new SPSite("http:/server");
oSPWeb
= oSPSite.OpenWeb();
Q.
What does a SPWebApplication object represent? Ans. The
SPWebApplication objects represents a SharePoint Web Application, which
essentially is an IIS virtual server. Using the class you can instigate high
level operations, such as getting all the features of an entire Web Application
instance, or doing high level creation operations like creating new Web
Applications through code.
Q.
Would you use SPWebApplication to get information like the SMTP address of the
SharePoint site? Ans.
Yes, since this is a Web Application level setting. You would iterate through
each SPWebApplication in the SPWebApplication collection, and then use the
appropriate property calls (OutboundMailServiceInstance) in order to return
settings regarding the mail service such as the SMTP address.
Side
Question: I got asked if there are other ways to send emails from SharePoint.
The answer is yes, there is. You can use the SendMail method from the SPutility
class to send simple emails, however it is not as robust as using the
System.Net.Mail functionality since it doesn’t allow things like setting
priorities on the email.
Q.
How do you connect (reference) to a SharePoint list, and how do you insert a
new List Item? Ans.
C#:
using(SPSite
mySite = new SPSite("yourserver"))
{
using(SPWeb
myWeb = mySite.OpenWeb())
{
SPList
interviewList = myWeb.Lists["listtoinsert"];
SPListItem
newItem = interviewList.Items.Add();
newItem["interview"]
= "interview";
newItem.Update();
}
}
Q.
How would you loop using SPList through all SharePont List items, assuming you
know the name (in a string value) of the list you want to iterate through, and
already have all the site code written? Ans. C#:
SPList
interviewList = myWeb.Lists["listtoiterate"];
foreach
(SPListItem interview in interviewList)
{
//
Do Something
}
Q.
How do you return SharePoint List items using SharePoint web services? Ans. In order to
retrieve list items from a SharePoint list through Web Services, you should use
the lists.asmx web service by establishing a web reference in Visual Studio.
The lists.asmx exposes the GetListItems method, which will allow the return of
the full content of the list in an XML node. It will take parameters like the
GUID of the name of the list you are querying against, the GUID of the view you
are going to query, etc.
Side
Question: I got asked how I built queries with the lists.asmx web service. In
order to build queries with this service, one of the parameters that the
GetListItems method exposes is the option to build a CAML query. There are
other ways to do this as well, but that was how I answered it.
Q.
How customizable is the user-to-user access? Ans. User permissions apply to an
entire Web, not to documents themselves. However, you can have additional sub
webs that can optionally have their own permissions. Each user can be given any
of four default roles. Additional roles can be defined by the administrator.
Can
each user have access to their own calendar?
Yes
there are two ways to do this,
by
creating a calendar for each user, or
by
creating a calendar with a view for each user
Q.
Can SharePoint be linked to a SQL database?
Ans.
This is possible via a custom application, but it not natively supported by
SharePoint or SQL Server.
Q.
What does partial trust mean the Web Part developer? Ans. If an assembly
is installed into the BIN directory, the code must be ensured that provides
error handling in the event that required permissions are not available.
Otherwise, unhandled security exceptions may cause the Web Part to fail and may
affect page rendering on the page where the Web Part appears
No comments:
Post a Comment