Offline Document Uploader in SharePoint 2010

A week ago i was just exploring Sharepoint 2010 Client Object model and have developed a utility which transfers all the documents from the windows folder to the Sharepoint document library. 

Following are the steps to develop Offline Document uploader in SharePoint 2010 using Client Object Model.

1. Create a menu item which opens files uploader utility from windows folder’s context menu.

                                        

In order to create custom menu item in windows, we have to place an entry into registry. 

I have first defined the two constant string variables as shown below that contains path to create a menu in the registry. You might have noticed that i have mentioned “Folder” at starting in both the values. This means that i want to create a context menu item at folder level. Otherwise if i place ” * ” it will be created at files, folder etc.

private const string MenuName = "Folder\\shell\\CMenuOption";
private const string Command= "Folder\\shell\\CMenuOption\Command";

Following is a code snippet that creates menu item at folder level. You can place it on any event. I have created two textboxes on a windows form i.e. txtMenuName and txtExecutablePath. In the txtMenuName textbox, i’ve  specified menu item name and in the txtExecutablePath i’ve specified the .exe path of an application which transfers file to sharepoint library.

Here is the complete code which creates a menu item into the registry.
           
RegistryKey regmenu = null;
            RegistryKey regcmd = null;
            try
            {
                regmenu = Registry.ClassesRoot.CreateSubKey(MenuName);
                if (regmenu != null)
                    regmenu.SetValue("", this.txtMenuName.Text);
                regcmd = Registry.ClassesRoot.CreateSubKey(Command);
                if (regcmd != null)
                    regcmd.SetValue("", this.txtExecutablePath.Text+ " \"%1\"");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString());
            }
            finally
            {
                if (regmenu != null)
                    regmenu.Close();
                if (regcmd != null)
                    regcmd.Close();
            }

Now there is a separate console application which sends the files from the folder path to the SharePoint document library. Following is the code snippet.

 
static void Main(string[] args)
        {

            String filepath =  args[0].ToString();
            Console.WriteLine(filepath);
            Console.WriteLine("Processing Documents");
            String[] files = Directory.GetFiles(filepath);

            String docLibrary= System.Configuration.ConfigurationSettings.AppSettings.Get("DocLibrary").ToString();
            String SPSiteURL= System.Configuration.ConfigurationSettings.AppSettings.Get("SPSiteURL").ToString();

            ClientContext context = new ClientContext(SPSiteURL);
            foreach (String fileName in files)
            {
                using(FileStream fileStream= new FileStream(fileName,FileMode.Open))
                {
                    Console.WriteLine("Uploading file = " + fileName);
                    Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, "/"+ docLibrary + "/" + Path.GetFileName(fileName), fileStream, true);
                    Console.WriteLine("Uploaded");
                }
            }
 }

Finally, When the user clicks on “Upload files to SP” a console application runs and uploads all the documents in the Sharepoint document library.

                                                 

Figure shows the Console Application uploading documents into SP doc library.

                                                 

                                                           Figure shows the documents uploaded in the SP doc library.





Advertisements

103 thoughts on “Offline Document Uploader in SharePoint 2010

  1. Hi, i believe that i saw you visited my site thus i came to “go back the prefer”.I am trying to to find issues to improve my web site!I guess its adequate to make use of some of your ideas!!

  2. I am extremely impressed together with your writing abilities and also with the structure in your weblog. Is that this a paid theme or did you customize it yourself? Anyway keep up the nice high quality writing, it’s rare to see a nice blog like this one today.

  3. Excellent read, I just passed this onto a colleague who was doing some research on that. And he just bought me lunch since I found it for him smile So let me rephrase that: Thanks for lunch! “We strain to renew our capacity for wonder, to shock ourselves into astonishment once again.” by Shana Alexander.

  4. Please maintain on posting such quality storys as this is a rare thing to uncover these days. I am always looking online for posts that can assist me. watching forward to an additional excellent site. Great luck towards the author! all the greatest!

  5. Thank you for sharing superb informations. Your web-site is so cool. I am impressed by the details that you have on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the information I already searched all over the place and simply couldn’t come across. What a perfect web-site.

  6. obviously like your web-site but you have to check the spelling on several of your posts. Several of them are rife with spelling problems and I in finding it very bothersome to tell the truth however I’ll surely come back again.

  7. But wanna say that this is handy , Thanks for taking your time to write this. “No kind of sensation is keener and more active than that of pain its impressions are unmistakable.” by Marquis de Sade.

  8. Thanks a bunch for sharing this with all folks you really recognise what you are speaking approximately! Bookmarked. Kindly additionally consult with my web site =). We will have a link alternate agreement between us!

  9. This could be definitely one of the very most useful websites. We’ve arrive around on that subject. Definitely good. I’m also an specialist in this field so I can recognize your effort.

  10. Thank you for the sensible critique. Me and my neighbor were just preparing to do a little research about this. We got a grab a book from our area library but I think I learned more from this post. I am very glad to see such fantastic information being shared freely out there.

  11. >Excellent submit, Im trying to get as considerably info as feasible at the minute for my final undertaking to make sure I get the very best outcomes feasible, so preserve it coming

  12. As soon as I detected this website I went on reddit to share some of the love with them. “So far as I can remember, there is not one word in the Gospels in praise of intelligence.” by Bertrand Russell.

  13. Good ñ I should certainly pronounce, impressed with your website. I had no trouble navigating through all the tabs as well as related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, site theme . a tones way for your client to communicate. Excellent task.

  14. I like this post, enjoyed this one appreciate it for putting up. “No trumpets sound when the important decisions of our life are made. Destiny is made known silently.” by Agnes de Mille.

  15. Thanks for a marvelous posting! I truly enjoyed reading it, you might be a great author.I will be sure to bookmark your blog and will come back very soon. I want to encourage you to definitely continue your great job, have a nice weekend!

  16. Wow, marvelous weblog layout! How lengthy have you ever been blogging for? you made running a blog glance easy. The entire look of your site is fantastic, as smartly as the content!

  17. hello there and thank you for your info – I’ve definitely picked up something new from right here. I did however expertise some technical points using this site, as I experienced to reload the web site many times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I am complaining, but sluggish loading instances times will often affect your placement in google and could damage your high quality score if ads and marketing with Adwords. Anyway I’m adding this RSS to my e-mail and could look out for much more of your respective exciting content. Ensure that you update this again soon..

  18. I saw a lot of website but I conceive this one has got something special in it. “Surfing is good for the soul, worries seems to drift away as you scan the horizon for the next wave.” by Ed Daley.

  19. I would like to use the ability of saying thanks to you for the professional advice I have often enjoyed going to your site. I am looking forward to the actual commencement of my college research and the overall preparing would never have been complete without visiting this site. If I may be of any help to others, I might be ready to help by way of what I have discovered from here.

  20. Thanks a ton for being my own instructor on this area. We enjoyed your article greatly and most of all cherished how you handled the areas I regarded as controversial. You are always incredibly kind to readers much like me and aid me in my existence. Thank you.

  21. Enjoyed examining this, very good stuff, thanks . “It is well to remember that the entire universe, with one trifling exception, is composed of others.” by John Andrew Holmes.

  22. Simply to follow up on the up-date of this subject on your web site and want to let you know simply how much I prized the time you took to publish this beneficial post. In the post, you really spoke on how to definitely handle this problem with all ease. It would be my pleasure to build up some more concepts from your web-site and come up to offer other individuals what I have learned from you. Thanks for your usual fantastic effort.

  23. I still can not quite feel that I could end up being one of those reading the important recommendations found on this blog. My family and I are truly thankful for your generosity and for providing me possibility pursue the chosen career path. Many thanks for the important information I managed to get from your web site.

  24. I like this weblog very much, Its a rattling nice post to read and receive information. “The one thing that doesn’t abide by majority rule is a person’s conscience.” by Harper Lee.

  25. Howdy are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding expertise to make your own blog? Any help would be really appreciated!

  26. I would like to take the ability of saying thanks to you for the professional instruction I have always enjoyed going to your site. I will be looking forward to the actual commencement of my college research and the entire groundwork would never have been complete without visiting your website. If I might be of any assistance to others, I might be thankful to help through what I have gained from here.

  27. I would like to consider the ability of thanking you for your professional suggestions I have continually enjoyed checking out your site. We are looking forward to the actual commencement of my school research and the entire preparation would never have been complete without checking out your website. If I can be of any help to others, I might be pleased to help by way of what I have learned from here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s