locked
Updating SharePoint excel file from Shared Drive excel file : MOSS 2007 RRS feed

  • Question

  • Hi All,

    I need to update a excel file which is in SharePoint from the same excel file modified in Shared drive. Version MOSS 2007

    Example: I have 3 excel files in shared drive folder called PARTIB. All 3 excel files are uploaded in SharePoint library under the same folder PARTIB. Multiple people will modify excel files in Shared folder which needs to be get updated to SharePoint. All 3 excel files are dependent on each other cell values. How can I achieve this? What are the problems I encounter RE: relative paths when somebody else open the file from SharePoint. The people who updates the excel files from Shared drive most of the times. What are my options?. Do I need to create windows service on the computer where these excel files are sitting and look for any file changes then upload to SharePoint. Share me some link where I have some code examples.

    Thanks,


    -Gautham

    Friday, February 24, 2012 5:04 PM

Answers

  •  

    Hi Gautham,

    You can first get the file from your shared drive folder, then upload it to your SharePoint List. Before upload, you should delete it in your SharePoint List.

    Here is sample code.

      using (SPSite Site = new SPSite("http://jack-7716f30e37:2012/personal/Test"))

                {

                    using (SPWeb Web = Site.OpenWeb())

                    {

                        Web.AllowUnsafeUpdates = true;

                        SPFile file = Web.GetFile("http://jack-7716f30e37:2012/personal/Test/TestFolder/abc.txt");

                        file.Delete();

                        file.Update();

                        String fileToUpload = @"C:\abc.txt";

                        Web.AllowUnsafeUpdates = true;

                        SPFolder myLibrary = Web.Folders["TestFolder"];

                        String fileName = System.IO.Path.GetFileName(fileToUpload);

                        FileStream fileStream = File.OpenRead(fileToUpload);

                        SPFile spfile = myLibrary.Files.Add(fileName, fileStream, true);

                        spfile.Update();

                        myLibrary.Update();

                    }

                }



    Thanks,

    Jack

    Wednesday, February 29, 2012 3:39 AM
    Moderator

All replies

  •  

    Hi Gautham,

    You can first get the file from your shared drive folder, then upload it to your SharePoint List. Before upload, you should delete it in your SharePoint List.

    Here is sample code.

      using (SPSite Site = new SPSite("http://jack-7716f30e37:2012/personal/Test"))

                {

                    using (SPWeb Web = Site.OpenWeb())

                    {

                        Web.AllowUnsafeUpdates = true;

                        SPFile file = Web.GetFile("http://jack-7716f30e37:2012/personal/Test/TestFolder/abc.txt");

                        file.Delete();

                        file.Update();

                        String fileToUpload = @"C:\abc.txt";

                        Web.AllowUnsafeUpdates = true;

                        SPFolder myLibrary = Web.Folders["TestFolder"];

                        String fileName = System.IO.Path.GetFileName(fileToUpload);

                        FileStream fileStream = File.OpenRead(fileToUpload);

                        SPFile spfile = myLibrary.Files.Add(fileName, fileStream, true);

                        spfile.Update();

                        myLibrary.Update();

                    }

                }



    Thanks,

    Jack

    Wednesday, February 29, 2012 3:39 AM
    Moderator
  • Hi Jack,

    Thanks for your reply. I am sorry for delayed reply as I was working another task.

    Regards,


    -Gautham

    Wednesday, March 14, 2012 2:21 AM