Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> Share Point >> Create a Document in SharePoint and add folder in SharePoint Document using C#
Create a Document in SharePoint and add folder in SharePoint Document using C#
Create a Document in SharePoint and add folder in SharePoint Document using C#


by Rohit Kesharwani on 12/5/2011 5:51:03 PM

Views: 3368       Comments: 0

Create a Document in SharePoint and add folder in SharePoint Document using C#

In this article I am going to explain or show you how to create a Document Library in SharePoint Server and how to add a folder in the Document Library by using C#:

To create a document library, follow these steps:

1)    Open a browser and log into Sharepoint.

2)    Click Site Actions and select More Options…

Create a Document in SharePoint and add folder in SharePoint Document using C#

3)    Under library, click Document Library and enter the document name as Personal Documents and click Create to proceed.

Create a Document in SharePoint and add folder in SharePoint Document using C#

You can see that your Personal Document (Document Library) is create successfully in browser.

Create a Document in SharePoint and add folder in SharePoint Document using C#

In the next step, we have to create a folder in a Document Library using C# application.

1)    Open Visual Studio and create a Console Application.

Create a Document in SharePoint and add folder in SharePoint Document using C#

2)    Browse Microsoft.SharePoint.dll and it to the References.

Create a Document in SharePoint and add folder in SharePoint Document using C#

3)    In the next step you have to change the properties of an application.

Create a Document in SharePoint and add folder in SharePoint Document using C#

4)    In the build option change the platform target into 64 bit (x64).

Create a Document in SharePoint and add folder in SharePoint Document using C#

1)     Then write the below code in the Program.cs file.

using System;

using System.Text;

using Microsoft.SharePoint;

 

namespace CreateFolderSPDoc

{

    class Program

    {

        static void Main(string[] args)

        {

            SPSite _MySite = new SPSite("http://rohit:34143/");

            SPWeb _MyWeb = _MySite.OpenWeb();

            SPDocumentLibrary _MyDocLibrary = (SPDocumentLibrary)_MyWeb.Lists["Personal
                                                                             Documents"
];

            SPFolderCollection _MyFolders = _MyWeb.Folders;

            string folderName = "rohitdoc";

            _MyFolders.Add("http://rohit:34143/Personal%20Documents/" + folderName +
                                                                                    "/");

            _MyDocLibrary.Update();

            Console.WriteLine("Docuemnt Created");

        }

    }

}


Output:

Create a Document in SharePoint and add folder in SharePoint Document using C#

After create a document you can see your folder (rohitdoc) is successfully added in the Document library (Personal Documents).

Create a Document in SharePoint and add folder in SharePoint Document using C#

Thanks for reading this article. I think this will help you a lot.

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Rohit KesharwaniRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 7472
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.