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

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.

Related

How do I programmatically add pages to a wiki library in Sharepoint?

My first question on stackoverflow, I hope I am following the rules.
Anyhow, as the title suggests, I need to figure out how to programmatically add pages to a wiki library. I set up upwards of 30,000 rows in Excel, VBA'd them into txt files containing html that portray articles, and now they are sitting in a folder with nowhere to go. They need to go into a wiki library on SharePoint, where they will be referenced by users in their articles. Two parts:
On single-file upload, cannot upload aspx files. I upload as txt or html and it goes fine. Then I try to change them to aspx. Illegal.
Cannot upload more than one file at a time. Once I figure out #1, this will be an issue.
I assumed there must be a way to mimic whatever the "wikification" process is for files programmatically. Microsoft's how-to on file uploading requires a Sharepoint Project, which requires VS Professional and running SharePoint locally. Neither of these is practical.
Thank you and godspeed.
You could write a small Powershell Script or Commandline application for example in C# or VB. Copy your files to the server and execute your script/app on the SharePoint server. Connect to your SharePoint like the following:
using Microsoft.SharePoint;
...
SPSite site = new SPSite("mysiteurl");
SPWeb web = site.OpenWeb();
// your code goes here
web.dispose();
site.dispose();
...
Then get the directory programmatically where your files reside.
If this was successful, loop through all files in your folder and upload them programmatically to the WIKI Library.
Sound complex, but if you search for the single topics, you will find a lot of solutions/code out there.
You could also write a Console Application which can connect remotely to the SharePoint Server without the need to be executed on the SharePoint itself. In this case you would need to use the Client Object Model (CSOM).
The Office 365 Patterns and Practices site is a great reference. It has a comprehensive sample for creating wiki pages using CSOM here

Dynamically Updating Excel Web Part Excel File

I have multiple Excel Web Parts in my SharePoint 2010 site. Each web part is connected to an Excel work book which is generated automatically by a scheduled task on a separate server. Given this, is there a way to automatically map a newly generated excel file to an existing excel web part instead of manually updating them?
I saw a tutorial but it uses the SharePoint dll and other dlls which are found from the SharePoint server itself and as far as I know, I can only execute these items if I have SharePoint installed locally. Is there any way to make it work without having to install SharePoint locally? By the way I was referring to this tutorial from MSDN.
Edit
I was able to create web parts programmatically using SharePoint.Client.WebParts but I'm having problems creating Excel Web Access Web Parts.
I was able to make it work by using the same concept found in this page.
All that I needed to do was properly escape quotation marks from the exported web part file in order to map the correct file.

Want to write HTML Content on a WebPart for 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.

ASP.net site sharepoint integration

I have created a test website that contains a single ASP.net index.aspx file that contains a gridview listing information from a MSSQL database.
I would like to have this made available as a webpart on our sharepoint intranet, how would I go about doing that?
You can just put your page under Template/Layouts and attach it to some SharePoint master page. It will look and feel like a regular SharePoint page.
Of course, that is good if you're into the quick&dirty approach :)
You will need to create a web part from the page you already have.
I would suggest isolating your gridview in a user control (ascx) instead of directly on the aspx page, it will be easier to use it in a web part that way.
To create a web part, you should probably start by downloading WSPBuilder or a similar tool that will do most of the work for you.
The following tutorial will give you the information you need on how to create a web part from a user control.
You should have no problem linking to your database or anything else. A web part behaves just like a user control.

Drag and Drop files into a SharePoint webpart to upload into DocLibrary

Is it possible to create a SharePoint (wss3 or MOSS 2007) webpart, to allow files to be dragged and dropped onto it, which would then upload the files into a predefined document library ?
I imagine that this would require some form of client side scripting (Ajax ?), but my knowledge in ajax is a bit sketchy.
From my exploration so far, I'm thinking:
User drags file onto 'drop zone' Webpart.
This action triggers some code
This code Loads the file into a SharePoint library (like this : Uploading a File to SharePoint)
Any pointers would be gratefully recieved
Many thanks.
Nick
Well,
What I'd do is, like you said, a web part with javascript that allow the user to drag and drop some files into a zone inside the webpart. Once the user has finished I'll upload those files after click on a Button of the webpart. I think is better to work with SharePoint in an unique transaction and not upload and delete files using AJAX. So, the drag and drop functionality can be done using some kind of javascript like Scriptaculous and the other one like a classic postback.
You might also want to look at another way to perform this. If you do it in a webpart, you will need to add that webpart in every sites where you want this fonctionnality to work. You might want to try Sharegate (www.share-gate.com). It's a end user tool that allows you to drag and drop file from your computer (or any SharePoint list / library) to any SharePoint library. By dropping the document inside the library, you will be ask to select a property template where you can define all the properties attach to your document. Not only you will drag and drop documents, but you will structure the information at the same time. Hope this was helpful!
Perhaps my reply is little bit irrelevant to your post!
I think upload files to SharePoint is not a painstaking job, the build-in feature is enough for us to upload files.
The trouble, I think, lies in the check in process, may be that is what you should do!
Altought maybe not that important now, but there is a SharePoint addon on CodePlex now
that allows files to be uploaded by Drag & Drop into SharePoint document libraries.
Available here: http://dndupload.codeplex.com/
Works in Firefox & Chrome, uses FileApi from HTML5, supports both SharePoint 2007 & 2010.

Resources