8 Replies Latest reply on Oct 28, 2010 5:49 AM by Ellizory Elli

    Problems with text files (.NET plugin)

    Ellizory Elli

      I have a plugin, written in C#, all works perfectly, except the thing, that when I changing text file (they are added to a vault) with StreamWriter, changes are not concidered, and after files are unlock, they are as they were before lock..

       

      What's interesting, if I open the file before unlock in notepad.exe and just click "save". It's all ok. So, I think, PDM doesn't get signal that "file has been changed", and don't update it to the server.

       

      So, what should I do?

       

      Thank you.

        • Re: Problems with text files (.NET plugin)
          Lee CS Young

          Hard to say without looking at some code. Can you post the relevant portion?

            • Re: Problems with text files (.NET plugin)
              Ellizory Elli

              Looks this way:

               

              IEdmFile5 file = ProjectFolder.GetFile("SubGroupList.txt");
              file.LockFile(ProjectFolder.ID, 0);
              File.Delete(ProjectFolder.LocalPath + "//SubGroupList.txt");
              StreamWriter SW =
              new StreamWriter(ProjectFolder.LocalPath + "//SubGroupList.txt",true);
              SW.WriteLine(Group + "," + SubGroup);
              SW.Close();
              file.UnlockFile(0, "", 2); // 2 - Remove local copy after check in


               

                • Re: Problems with text files (.NET plugin)
                  Lee CS Young

                  Try SW.Flush(); before Close().

                   

                  SW.Flush();

                  Sw.Close();

                    • Re: Problems with text files (.NET plugin)
                      Ellizory Elli

                      I tried flush, it didn't help

                      And as i understand Close cause autoflushing

                        • Re: Problems with text files (.NET plugin)
                          Lee CS Young

                          You're right, Close does call flush before closing the stream.

                           

                          Have you tried editing the existing file instead of deleting it and creating it again? (According to MSDN, if the file exists the file is overwritten so you don't need to call File.Delete anyway...)

                            • Re: Problems with text files (.NET plugin)
                              Ellizory Elli

                              well, so what should I try? How according to MSDN I can edit text file w\o overwriting it?

                              .. as I said, after Closing stream and before Unlocking file I open it in notepad for an only purpose - to save it. And it works...

                                • Re: Problems with text files (.NET plugin)
                                  Lee CS Young

                                  You can edit a file using StreamWriter and StreamReader.

                                   

                                  This code works fine here. The date changes each time.

                                   

                                  using System;
                                  using EdmLib;
                                  
                                  namespace EDPMStreamWriterTest
                                  {
                                      class Program
                                      {        
                                          static void Main(string[] args)
                                          {
                                              IEdmVault5 vault = new EdmVault5Class();
                                              vault.Login("lyoung", "ICanHazCheezBurgerz??", "EPDM");
                                              if (vault.IsLoggedIn)
                                              {
                                                  IEdmFile5 file = vault.RootFolder.GetFile("testdoc.txt");
                                                  if (file != null)
                                                  {
                                                      file.LockFile(vault.RootFolder.ID, 0);
                                                      using (System.IO.StreamWriter sw = new System.IO.StreamWriter(file.LockPath))
                                                      {
                                                          sw.WriteLine(DateTime.Now);
                                                      }
                                                      file.UnlockFile(0, "none", 2);
                                                  }
                                              }
                                          }
                                      }
                                  }
                                  
                                    • Re: Problems with text files (.NET plugin)
                                      Ellizory Elli

                                      It really works fine, though it is the same as mine (Deleting file was testing option)

                                      -------

                                       

                                      Now, I finally have found out , that problem was in the case when I've just created file:

                                       

                                                              file = (IEdmFile5)ProjectFolder.Vault.GetObject(EdmObjectType.EdmObject_File, ProjectFolder.AddFile(0, "", "GroupList.txt"));

                                       

                                      this way AddFile creates new file (don't copy existing) in the vault.. and my attempts to write some data to a newly created file was failed in 90% (it was strange, that sometimes they left).

                                       

                                      So I replaced actions - first, I make a local file, write there data, and then use ProjectFolder.AddFile(0, ProjectFolder.ID+"\\GroupList.txt", ""), so it was copied but not created..

                                       

                                      Maybe this info will be useful for someone, I don't know..

                                       

                                      However, thank you