Want to write HTML Content on a WebPart for Sharepoint - sharepoint

In developing Sharepoint Webpart, if I need to add HTML Content to the output of my Web Part, right now I do it like this :
this.Controls.Add(new LiteralControl("<html content>");
If I need to output a large HTML Content with Data in it, I need to instantiate a lot new Literal Contents then there is a problem, that it will make my process slow and memory consuming.
Please tell some alternatives to this approach.

Just use a visual webpart where you get to use the WYSIWYG designer and if it needs to be deployed in a Sandboxed environment you can download one from the Power Tools extension.
Oh God, writing all that markup from code is a nightmare. By using a visual webpart you can make amazing looking webparts.
If you are going to use your own scripts or CSS files just create mapped folders for them and set the deployment option to their path.

You can approach this problem by analysing webpart rendering time by using Developers DashBoard (only in SharePoint 2010). To enable this you should use powershell code like this:
$svc=[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ddsetting=$svc.DeveloperDashboardSettings
$ddsetting.DisplayLevel=[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$ddsetting.Update()
When DD is enabled use this instruction to chceck your rendering time on server side:
http://blogs.technet.com/b/speschka/archive/2009/10/28/using-the-developer-dashboard-in-sharepoint-2010.aspx
You can also use monitored scopes (SPMonitoredScope) to check parts of your code which can take most part of rendering.

Related

where to put the C# code if you don't want to use WEB PART in SharePOINT via iSharePoint designer

I'm site collection administrator for a site in SharePoint 2010. I'm using SharePoint Designer 2010.
I'm not allowed to use WebPart etc. I created a some HTML pages and Javascript files and using the LISTDATA.SVC to update my lists and uploading documents to my document library programmatically via Javascript.
Till here it's fine. Now when I click a button, I need to call a webservice (*.ASMX) file and need to use file.readallbytes and call the webservice with this bas64 encoding stuff etc. a 20 lines of C# code.
I can't write these in Javascript so I need to write this in C#, Which I already wrote, but where do I put my 20 lines of C#.NET code? There is no code behind file.
I just see default.aspx.... If I create default.aspx.cs file and add button event handler will this work or how can I get this working?
I can't change anything in Central Admin (not access to it). I've just full SCA right.
I googled and find something "PageParserPath" but it's not clear?
http://msdn.microsoft.com/en-us/library/bb862025%28v=office.12%29.aspx
I've just 2 months exprience with SP, so please be more concreet when responding.
please advice where and how to put the C# code?
For security reasons, SharePoint designer removes almost all C# code that you put directly into the aspx page. You will need to either use Visual Studio to build a web part or find a JavaScript solution. What you're asking is very likely possible through JS, so you might consider posting a new question giving your C# code and asking for help doing the same thing with JS.

I want to implement SharePoint, but I want to design it my way

I am aware of a program called "SharePoint Designer 20xx), and I would like to know if any of you have modified the default master page to make it.. less confusing and more simplistic. Can this be however I want it or is there limitations?
I also found this:
http://www.expertsharepointconsulting.com/images/Blue%20Large.PNG
I would like to implement a design similar to this! If I were to download a "Free sharepoint master page", would this design only work for the main page of SharePoint? as in if I were to go from the newly added masterpage, to a page called "reports", would it be completely different? If so how can I get around this?
You can create customized masterpages whichever way you want. Usually you don't touch the default ones, specially because you can break some system pages with that. Just create new ones from them or from the minimum.master one.
As an example of a Sharepoint Website using a very customized master page I can point you to a publishing website project I was involved for a Portuguese company: http://www.ana.pt/en-US/Pages/Homepage.aspx
It's all Sharepoint 2010...and it is fully customized
You can of course use the same template for all pages, just have to set it on the root site and say that all sub sites inherit from it.
To achieve the level of design changes you see on that web site you have to build new master pages, page layouts, use JS, CSS and user controls (the website uses little to no web parts).
we don't use Sharepoint designer because that would mean the files becoming unghosted, which can be pain sometimes, and sharepoint designer is not a very good tool.
The way we do it is by implementing everything on visual studio and deploying it via WSP packages. This way everything stays ghosted on the file system. You can check an example here:
http://mihirsharepoint.wordpress.com/2012/11/23/creating-custom-master-page-in-visual-studio-and-deploy-it-to-the-sharepoint-site/

Sharepoint: Modify the page template of views

I have a sharepoint list with several views. I can modify the view pages (such as AllItems.aspx) via the sharepoint designer. However I would prefer to modify the underlying template instead.
Now I could directly modify the default view page template located in templates\pages\viewpage.aspx but this would affect the whole sharepoint installation.
I would rather make a copy of this template and make my list (or views) point to it. Is there a way I can accomplish this?
Note: The list/views were created via the Web UI without any custom XML.
Check out this blog:
http://weblogs.asp.net/soever/archive/2006/11/11/SharePoint-Solution-Generator-2D00-part-1_3A00_-create-a-site-definition-from-an-existing-site.aspx
Basically, use the sharepoint solution generator to create a VS solution of your SharePoint list. The solution will contain a file called schema.xml that defines the list and associated views. You can then customize the aspx pages like viewlist.aspx and point the schema at your custom pages. When you deploy the solution/feature it will deploy your custom pages with it.
There's really a wealth of info out on the internets, it's just difficult to find when you don't know what you're looking for. But this should get you started in the right direction.
Also, in my experience, once you create the solution you should port it (read: copy teh contents) into an STSDEV project. STSDEV really shows you what's happening behind the scenes, whereas the other VS tools for SP development can do some hand-waving magic which will leave you in the dark when things go wrong. Just my 2 cents.

MOSS 2007: Displaying data from SQL Server Database

I have a requirement to select some data from a table in a database (SQL Server) and display it on a page in a SharePoint site (MOSS 2007).
I have a little bit of experience of MOSS, so I know I have a couple of options:
BDC
SSRS
or possibily even a custom ASPX page.
I've never really worked with any of these. Can anyone advise on the +/-'s of each?
It all depends on what functionality is required once the table is displayed in SharePoint. Do you need extra bells and whistles or is a dump of the data adequate? (Think about the future as well.) Here's some thoughts...
Business Data Catalog (BDC)
If you want to nicely integrate the SharePoint look and feel with your data as well as get some cool functionality, BDC is a good solution. There is no need to program anything and these are the features you get. However if this data will only be used once in one way then it is probably overkill.
You would need to roll your own XML description of the data so SharePoint knows how to pull it from the database (or use something third party like Lightning Tools). As Colin mentioned it requires the Enterprise license of MOSS.
SQL Server Reporting Services (SSRS)
If Reporting Services is already available for use then this is the quickest and simplest solution. It works well but can get painful as more advanced features are required in your reports.
You should be able to use the Report Designer wizard to point to your table and set everything up for you. There are SSRS web parts that can be used within SharePoint, or indeed you can run SSRS inside SharePoint using SharePoint integration mode.
Application Page
This method Steven mentioned lets you integrate an ASP.NET application into SharePoint (such that it can be accessible by a URL within your SharePoint site). This allows anything that ASP.NET does, and the code-behind will be aware of SharePoint so you can tap into that if needed as well. The cons here are code access security and deployment.
See this webcast for how to do it.
Web Part
Similar to developing an application page but much more integrated with SharePoint. A custom web part is very powerful and allows you to integrate ASP.NET code on a SharePoint page. As you would know web parts can be dragged to whatever location and give a consistent properties pane. Again, code access security and deployment needs to be considered.
If you like designer view in Visual Studio then be aware this isn't the approach that Microsoft push. You can however use something like SmartPart where you would develop your custom app as a user control and the SmartPart wraps it into a web part. I'm used to doing it the MS way now and actually prefer the additional control this gives, however it can take more time.
Page Viewer Web Part
If you don't want to touch your SharePoint installation at all then have a look at this web part. It takes a URL as parameter and displays an IFrame containing the page that would be your report, either in SSRS or standard ASP.NET.
The downside from this lack of integration is problems with sizing the IFrame, and possible security warnings from the browser if accessing the URL in a different domain.
Don't forget the DataView Webpart. It has a pretty small developement footprint and works really well as a first "cut" if you are unsure as to how hardcore you need the final result to be.
It renders using XSLT, giving you full control of the final HTML, so it can do some pretty things with Javascript and co.
For a very simple example of charting.
Have you ever used the .NET Framework do develop webpages?
MOSS 2007 uses this framework for master / template files.
So your best choice would be to create an ASPX template file to display the results on the webpage.
BDC is the way to go if you want to keep it "strictly Sharepoint". The problem is, it is only included in the Enterprise edition of SharePoint. If you have the Standard edition, you could go for SSRS and the SSRS webpart, or, create your own webpart. That way you can use your data display anywhere in your site and it's also ASP.NET compatible.
As Nat said - if all that is needed is to display some data from a database on a page - the DVWP is a great solution. Just open your page in SharePoint Designer, add the database connection, and drop the web part on your page. You can use any of the several pre-formatted layouts, or design/tweak your own so the data is displayed as you need.
Relatively straightforward, lots of HowTos online, and far faster/easier to setup than something like BDC.

SharePoint: Back up single page

I need to back up a sharepoint web page which containts web parts and other html tweaks. I would like to keep a back up of the page itself with the web parts in the appropriate places, is this possible? Right now I just opened SharePoint designer, opened my page and saved as to my hard drive. Is there another way? Is this a complete back up of the page? Thanks.
I do the same for small changes and it has worked fine for me up to now. That said the only offical way to do it is use Microsoft's Data Protection Manager software which will let you backup/restore individual pages.
Of course you can go the doclib where the page is stored and use the ECB SendTo>>Download a copy
the interesting part of this approach is that you get the ASP.NET markup (w/server control specs)...

Resources