Windows Service to upload files on SharePoint server. Some questions - c#

I would like to upload some files on a server Share Point.
My questions are:
1) I started developing my project as a Windows Service but I read several parts of this WebService. It's mandatory that it's be a WebService?
2) I added the references to. Dll take it from my SharePoint Server (as seen in most discussions) but a little read more shares can not be tested if not solely on where you installed SharePoint Server. Right or there are alternative methods to do this? And also, when we deliver the service, can I install the latter on a machine where SharePoint is not installed (it seems a trivial question, but it seems strange not being able to test
but you install it).

You can only reference SharePoint 2007 assemblies from code that is running on the machine where SharePoint is installed (if you were using SharePoint 2010, you could take advantage of the Client Object Model).
Only the part of your solution that is directly interacting with SharePoint has to be created as a web service. You should create a web service with basic methods like UploadFileToLibrary, deploy it to SharePoint machine and then call these methods from the client (it can be an ASP.NET page or desktop application).
As Kit Menke pointed out in a comment below, it is possible that built-in SharePoint web services will be sufficient for you needs and you won't have to create a custom one:
Upload a file to SharePoint through the built-in web services
Copy.CopyIntoItems method

Related

SharePoint Hosted App 2013 - ASPX with c# code behind

I have a small question which ends in a big topic.
Is it possible - and yes how - to use C# code in a SharePoint 2013 Hosted App?
I tried to have a .asmx file within my project.
Then I get this error.
#"Error 1
CorrelationId: 9c1ea930-a131-4f5b-bff5-8a1a61fe34d9
ErrorDetail: There was a problem with activating the app web definition.
ErrorType: App
ErrorTypeName: App Related
ExceptionMessage: Microsoft.SharePoint.SPException: Exception from HRESULT: 0x81070964 ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x81070964
And then I tried a few tutorials like...
http://chuvash.eu/2012/02/13/custom-httphandler-in-sharepoint-for-getting-dynamic-javascript-code/
http://blogs.msdn.com/b/kaevans/archive/2010/08/04/deploying-an-asp-net-httphandler-to-sharepoint-2010.aspx
http://social.technet.microsoft.com/wiki/contents/articles/24194.sharepoint-2013-create-a-custom-wcf-rest-service-hosted-in-sharepoint-and-deployed-in-a-wsp.aspx
But sometimes I didn't understand correctly or sometime I have other problems during compile everything.
I had a problem with getting assembly id/name, too. Because there was no compiled DDL File for the project.
What I want in general?
A .app file with a SP Hosted App (for SP 2013) which includes a web service for SP Client Object Model.
So I thinking about using the "default.aspx" with CodeBehind. So I could execute scripts "behind" the aspx. But then it couldn't find the assembly... Or there was something else.
Could anyone help me? If you have some ideas you could !please! provide them to me. Thank's!
SharePoint hosted Apps doesn't allow server side code to be excuted on the server, this is the whole idea of SharePoint Apps, nothing should be executed in the SharePoint Front End Servers. Unlike Farm solutions, SharePoint Hosted Apps runs on the client and can only access SharePoint resources through a predefined set of services that can be called either using REST or JSOM.
If you need a custom code, you can create a WCF service, deploy it under ISAPI and call it from your App, but this will not be doable in SharePoint online.
As for your question, you can use ASPX pages of course, but you will never put a code behind for it, as these pages are stored in a Pages Library and by design, it is stored in the content DB, so any code execution is denied.
Only aspx pages that are stored on hard disk like the _layouts pages can have a code behind.
SharePoint App runs in client context. You can create SharePoint App just using JS, HTML, CSS, JSOM. You cannot use C# for App (excluding CSOM, you can use it for creation remote event receiver for example)
If you need to implement some functionality to on-premise version of SharePoint, use traditional server-side solutions, not App.
It's important to understand the difference between SharePoint-hosted Apps and Provider-hosted Apps:
SharePoint-hosted Apps
SharePoint-hosted apps, or apps where all components are hosted on either an on-premises or Office 365 SharePoint farm. SharePoint-hosted apps are installed on a SharePoint 2013 website, called the host web. They have their resources hosted on an isolated subsite of a host web, called the app web. The App is created using HTML/JavaScript with CSOM or REST calls
Provider hosted apps
Provider-hosted apps for SharePoint include components that are deployed and hosted outside the SharePoint farm. They are installed to the host web, but their remote components are hosted on another server. The App run in a server that is external to SharePoint's. It has its own infrastructure and the Provider is responsible for keeping it running. They allow you to use Server Side code and uses the .NET CSOM.
This image will give you an overview of different Hosting solutions:
Visit the following link for more information:
https://msdn.microsoft.com/en-us/library/office/fp179887(v=office.15).aspx
The SharePoint Add-in model uses ASPX pages, which can also include ASPX controls. However any methods called are restricted to client-side scripting - i.e. JavaScript and SharePoint's JSOM (JavaScript Object Model), which is a subset of the Client Side Object Model.

Running Web Application Locally (Offline) & without IIS

I'm trying to understand if there is a way to make a web application run on the local computer(browser) without IIS.
My main objective is to transform my web application (that is on the internet) to a software that runs on the local computer without using the internet and without IIS.
My idea is to distributed my webapp between my colleagues and not forcing them to work online and not needing an internet connection.
I have a MVC web app with 3 pages and a couple of methods on the server side.
The idea of the application is to get proprieties from a form that I implemented on one of the pages of my web application and transform the proprieties on the client side to JSON and send it to the server, the server will generate XML file according to the JSON object and let the client download the XML file that were generated.
The flow of it:
1.The Client fill the form in my site.
2.The form become JSON object on the client side.
3.The JSON object that stored the properties of the form(filled by the client) is send to the server.
4.The server get the JSON object and generated XML document from it.
5.The client download the generated XML file.
Very simple web application.
I know that I can run HTML page by clicking it and the page will display on the browser but I need the server side to be working too to carry out actions.
So my question is : How can I make my web application run without internet ?
With the constrains:
No IIS required.
Working with .NET 4.0. (OWIN 2.0 - Not good)
No internet require.
No installation required to the computer ill pass this web app.
The server side code wont be expose when I send this application to my friends.
I read a couple of articles about OWIN, SingalR, Cassini and WCF but its all very vague...
If someone could provide me with a guide lines it will be very helpful.
Thanks a lot.
You can definitely self host a .NET web application using OWIN. Unfortunately documentation and information about it is vague and confusing at best. The fact that you're using MVC makes it somewhat easier as you may be able to directly use the self-host packages from Nuget for self hosting Web API. There may be similar packages for MVC.
I don't have recent experience but a Nuget search for "MVC Self Host" should yield some results.
Below is a link with an example. But the term you are looking for is definitely "self host". It can be done via a console window or (more complex) a windows service. It will likely use some form of OWIN but you can probably find some startup code to copy and paste into your project, usually in the form of a Startup.cs file.
http://www.c-sharpcorner.com/UploadFile/4b0136/working-with-owin-hosting-and-self-hosting-in-Asp-Net/

MOSS 2007 exporting documents using C# on XP machine

I looked at forums and some blogs to find out my answer but could not so posting here.
We have MOSS 2007 and a library where we have documents are stored, I would like to run a client utility which runs a day and export all documents imported on that day along with metadata(Column names)
I don't want to install SharePoint server on VHD or on my development environment because I don't think that just for this cause I need to to have Dev SharePoint environment. I don't want to develop this on my development SharePoint environment and give it to my SharePoint team to deploy on server because I feel I should be able to do just on my XP machine.
As SharePoint object model is available, why I cant take missing dll from server and write a small C# utility to export documents to file system? I assume I should be able to do this with SharePoint web service but my question is can I do with SharePoint object model on my XP machine? I don't want to ask my admin to use stsadm to do required work as part of script.
In SharePoint 2007 there is no support for client-side access to the (server) object model. You have to use web services to comply with the requirements you've presented.
Also, it is not possible to take SharePoint DLLs to a client machine without SharePoint installed, and compile—or even run—code with them. It might be possible to achieve compilability, but the process is tedious and makes no sense at all providing it won't ever run on such machine.
You don't need any DLLs from SharePoint 2007 to use web services.
Getting just DLLs be painful for development - you'll be able to compile your code, but to run/debug you still need full installation of SharePoint.
Note that there is special https://sharepoint.stackexchange.com/ dedicated to SharePoint questions.

SharePoint Server Object Model and WCF

I was trying to access an API which contains SharePoint Server Object Model codes from a project inside WCF server. My intention is to download a document which is on SharePoint server.
My codes are inside WCF server. SharePoint server is another server.
Whenever I try to access the server using
SPSite.Exists(new Uri(spServerURL))
It does not know the server. So when I change the WCF application pool to run under the Farm admin account, it works well.
Is it OK to do like that or it will be a security breach?
How should I try to access the document ?
I think it will be better if you'll deploy your service to existing SharePoint web applications. So your service will work under SharePoint app pool account, so, you will not have problems with permissions of your service for SharePoint. Also it will be available for your SharePoint solutions from mapped path like this http:////_vti_bin/. This is useful, when you need to acces it from web contecxt you can use just relative path /_vti_bin/.
Check this link for more information about service development for SharePoint 2010.

Reference SharePoint dll from within a Silverlight Application?

I need to build an external upload utility to send files up to SharePoint 2010. However, I can't reference SharePoint to call all of the code needed to work with a document library.
Is there any way to make this happen inside Silverlight?
All answers are true and valid, however there IS a Client Object Model for SharePoint that you can use with Silverlight aswell. Here is a great tutorial to get you started.
This is rather not possible. Silverlight executes under a sandboxed environment with no direct access to server-side APIs.
Instead, create a WCF service at the server side, reference the Sharepoint DLL from within the service and call the service from Silverlight.
Silverlight runs on the client, not on the server, so you can't reference the SharePoint dlls. You would need to build a server-side service that uses the sharepoint dlls and then call that service from Silverlight.
There are built-in sharepoint developer entry points which I reference in my blog post here. You could probably use these instead of using the sharepoint dll.

Categories

Resources