Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to generate a unique name to my application instance?

how to generate a unique name to my application instance?

Scheduled Pinned Locked Moved C#
csharpcsstestingtoolsxml
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abhiram_nayan
    wrote on last edited by
    #1

    hey friends, am developing an automation addin to excel using c#, upon building and running my project, an excel instance opens up. Now, i have somethings relevant to this excel to save to an xml. Thus, I need a seperate xml to every seperate instance of excel. For later uses I should be able to save my excel sheet and upon opening this saved sheet, I should be able to read from the corresponding xml file too! I am generating the xml file in my code itself. Thus, I need a unique name/id to name these "excel---xml" pairs and thus be able to read from the corresponding xml whenever i open any saved sheet. more or less like.. i need... book1.xls----book1.xml & book2.xls----book2.xml & so on... regards.

    L M 2 Replies Last reply
    0
    • A abhiram_nayan

      hey friends, am developing an automation addin to excel using c#, upon building and running my project, an excel instance opens up. Now, i have somethings relevant to this excel to save to an xml. Thus, I need a seperate xml to every seperate instance of excel. For later uses I should be able to save my excel sheet and upon opening this saved sheet, I should be able to read from the corresponding xml file too! I am generating the xml file in my code itself. Thus, I need a unique name/id to name these "excel---xml" pairs and thus be able to read from the corresponding xml whenever i open any saved sheet. more or less like.. i need... book1.xls----book1.xml & book2.xls----book2.xml & so on... regards.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      How about Guid.NewGuid() ?

      A 1 Reply Last reply
      0
      • L Lost User

        How about Guid.NewGuid() ?

        A Offline
        A Offline
        abhiram_nayan
        wrote on last edited by
        #3

        but hey, i should be able to save the sheet and re open and re use the sheet and its corresponding xml right... this guid.newguid() would give every time a new globally unique identifier. This way, how can I fetch the guid of my currently opened sheet(which was saved earlier) so that I'll open the correct xml?

        L 1 Reply Last reply
        0
        • A abhiram_nayan

          but hey, i should be able to save the sheet and re open and re use the sheet and its corresponding xml right... this guid.newguid() would give every time a new globally unique identifier. This way, how can I fetch the guid of my currently opened sheet(which was saved earlier) so that I'll open the correct xml?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I think you must create a new Guid using Guid.NewGuid() and put that Guid in your excel sheet and xml. Then if you open it, just open the excel sheet, get the guid from that sheet, and find the same guid in xml.

          A 2 Replies Last reply
          0
          • A abhiram_nayan

            hey friends, am developing an automation addin to excel using c#, upon building and running my project, an excel instance opens up. Now, i have somethings relevant to this excel to save to an xml. Thus, I need a seperate xml to every seperate instance of excel. For later uses I should be able to save my excel sheet and upon opening this saved sheet, I should be able to read from the corresponding xml file too! I am generating the xml file in my code itself. Thus, I need a unique name/id to name these "excel---xml" pairs and thus be able to read from the corresponding xml whenever i open any saved sheet. more or less like.. i need... book1.xls----book1.xml & book2.xls----book2.xml & so on... regards.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Why not use something like YourApplication00001.xls Keep an internal counter somewhere and increment the 1 evertime it is opened. You could even ask the user for the name to use if you wanted to.

            Never underestimate the power of human stupidity RAH

            A 1 Reply Last reply
            0
            • M Mycroft Holmes

              Why not use something like YourApplication00001.xls Keep an internal counter somewhere and increment the 1 evertime it is opened. You could even ask the user for the name to use if you wanted to.

              Never underestimate the power of human stupidity RAH

              A Offline
              A Offline
              abhiram_nayan
              wrote on last edited by
              #6

              well, he might not save certain instances at all... nd i feel it's weird to ask something like.. would you like to save this? If yes, enter the name, because it's quite variable, if in the last moment he decides to save... hence i need something like... MyApplication.guid() or something.. I've tried using Hinstance..Index.. blah blah.. but no help.

              M 1 Reply Last reply
              0
              • L Lost User

                I think you must create a new Guid using Guid.NewGuid() and put that Guid in your excel sheet and xml. Then if you open it, just open the excel sheet, get the guid from that sheet, and find the same guid in xml.

                A Offline
                A Offline
                abhiram_nayan
                wrote on last edited by
                #7

                erm.. will have to work on it..

                1 Reply Last reply
                0
                • L Lost User

                  I think you must create a new Guid using Guid.NewGuid() and put that Guid in your excel sheet and xml. Then if you open it, just open the excel sheet, get the guid from that sheet, and find the same guid in xml.

                  A Offline
                  A Offline
                  abhiram_nayan
                  wrote on last edited by
                  #8

                  Is there a way I can know whether my Instance(excel) is saved or not?! So that I can use in the OnDisconnection() part of the code?!

                  1 Reply Last reply
                  0
                  • A abhiram_nayan

                    well, he might not save certain instances at all... nd i feel it's weird to ask something like.. would you like to save this? If yes, enter the name, because it's quite variable, if in the last moment he decides to save... hence i need something like... MyApplication.guid() or something.. I've tried using Hinstance..Index.. blah blah.. but no help.

                    M Offline
                    M Offline
                    Mycroft Holmes
                    wrote on last edited by
                    #9

                    I would assume that the c# DLL can get access to the user.applicationdata folder so you should be able to store the number in there. Add enough 0 so you can not reasonably run out. Not sure an xl add in has that access though.

                    Never underestimate the power of human stupidity RAH

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups