【问题标题】:Is there a way to download a file from sharepoint, edit it and uploading back up within the application?有没有办法从共享点下载文件,编辑它并在应用程序中上传备份?
【发布时间】:2014-06-06 09:04:27
【问题描述】:

我正在开发一个应用程序 c#(winforms),它可以从您的计算机打开一个 xml 文件,对其进行编辑(删除节点、添加新节点和更改现有节点),当然还可以将其再次保存到您的计算机。

该 xml 文件已上传到我们网站的 sharepoint 2007 库。 所以我想省去在电脑上保存文件然后手动上传的麻烦。

有没有一种方法可以不用在本地打开文件,而是从共享点库下载相同的文件并打开它进行编辑,然后将更改保存到库中的文件?

使用 Visual Studio Ultimate 2010,该应用使用 .net 3.5

谢谢。

【问题讨论】:

    标签: c# visual-studio-2010 sharepoint sharepoint-2007


    【解决方案1】:

    这里有M$ demo app,它可以将文件下载/上传到 SP2007。最重要的部分:

    下载:

    using (SPSite site = new SPSite(txtSite.Text)) 
                { 
                    using (SPWeb web = site.OpenWeb()) 
                    { 
                        SPFolder myLibrary = web.Folders[txtDocLib.Text]; 
    
                        foreach (SPFile file in myLibrary.Files) 
                        { 
                            if (file.Name == comboBox1.SelectedItem.ToString()) 
                            { 
                                byte[] bytes = file.OpenBinary(); 
    
                                try 
                                { 
                                    FileStream fs = new FileStream(dialog.FileName, FileMode.Create, FileAccess.ReadWrite); 
                                    BinaryWriter bw = new BinaryWriter(fs); 
                                    bw.Write(bytes); 
                                    bw.Close(); 
                                    MessageBox.Show("File downloaded to: " + dialog.FileName); 
                                } 
                                catch (Exception ex) 
                                { 
                                    MessageBox.Show(ex.Message); 
                                } 
    
                            }                             
                        } 
                    } 
                }
    

    上传:

    using (SPSite oSite = new SPSite(txtSite.Text)) 
            { 
                using (SPWeb oWeb = oSite.OpenWeb()) 
                {                     
                    SPFolder myLibrary = oWeb.Folders[txtDocLib.Text]; 
    
                    // Prepare to upload 
                    Boolean replaceExistingFiles = true; 
                    String fileName = System.IO.Path.GetFileName(txtSelectedFile.Text); 
                    FileStream fileStream = File.OpenRead(txtSelectedFile.Text); 
    
                    // Upload document 
                    SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles); 
    
                    // Commit  
                    myLibrary.Update(); 
                } 
            }
    

    【讨论】:

      猜你喜欢
      • 2022-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      相关资源
      最近更新 更多