Link to home
Start Free TrialLog in
Avatar of thdm1907
thdm1907

asked on

Invalid DOS path: $/ error when get items from sourcesafe

Hello,
I'm trying to get a list of items under root in C#. Here's the code:

vssDatabase = new VSSDatabase();
vssDatabase.Open(txtIniPath.Text, username, password);

IVSSItem vssProj = vssDatabase.get_VSSItem("$/", false);
IVSSItems items = vssProj.get_Items(false);
foreach (VSSItem itm in items)
{
MessageBox.Show(itm.Spec);
}

I got an exception at the line ==> IVSSItems items = vssProj.get_Items(false);
saying "Invalid DOS path: $/" . I'm sure there are items under root.
Any ideas why I'm getting the exception?

Thanks.
Avatar of Fittsim
Fittsim

Try adding the @

IVSSItem vssProj = vssDatabase.get_VSSItem(@"$/", false);

I was doing a project recently with the DirectoryInfo and thats the character I needed to make it work you might also need todo

IVSSItem vssProj = vssDatabase.get_VSSItem("$//", false);

I was doing
DirectoryInfo di = new DirectoryInfo(@"c:\") and without the @ I would have had to do DirectoryInfo di = new DirectoryInfo("c:\\")

Hope it helps.
Avatar of thdm1907

ASKER

Thank you for your help, I really appreciate it :)

I did try both ways but it still doesn't solve my problem.
I did a little more reading with VSSDatabase, which I have not used (yet, it is comeing up in the future)

http://www.c-sharpcorner.com/Code/2003/Jan/AutomateVSS.asp 

has a fairly good example with some explination on getting files from VSS, the string path you are using to open up the (I belive ini file) needs to have the @ in front of it  string myDir = @"c:\vss\myVss.ini" or you need to set it up like string myDri = "c:\\vss\\myVss.ini"  
Thats really the only thing I can think of with this error. that or your true rootpath may not be "$/".  Definatly check out the link and see if it inspires you to find out whats going on.

Im currently working on a tool that uploads files from the dev server to the live servers, and soon I will have to check files out, so no changes can be made by accident during the upload. (the tool is so my users can upload content w/o breaking the site).



I did went through that site when I tried to look up information about VSS stuff in C# too. The error seems simple but it's weird because I did try all the things you said.
Here is my version of the code right now, values are hardcoded for testing:

form2.cs:

           try
            {
                vssDatabase = new VSSDatabase();
                inipath = "C:\\Downloads\\srcsafe.ini";
                vssDatabase.Open(@inipath, "myUser", "myPW");
               
                MessageBox.Show("dbName: " + vssDatabase.DatabaseName + "\nSSini: " + vssDatabase.SrcSafeIni +
                     "\nproj: " + vssDatabase.CurrentProject);
               
                this.Close();
                return;
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show(ex.Message + "\n-> " + ex.StackTrace);
            }
            catch (System.Net.WebException we)
            {
                MessageBox.Show(we.Message + " -> " + we.StackTrace);
            }

form1.cs:
            vssDatabase = vssForm.vssDatabase; //this is form2.cs
            vssRoot = vssDatabase.get_VSSItem("$//", false);

            try
            {
                if (vssRoot.Type == (int)VSSItemType.VSSITEM_FILE)
                {
                    MessageBox.Show("Item is a file!");
                    return;
                }
                else
                {
                    MessageBox.Show("current local: " + vssRoot.LocalSpec);                    
                    IVSSItems items = vssRoot.get_Items(false);                    
                    foreach (VSSItem itm in items)
                    {
                        MessageBox.Show(itm.Spec);
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show(ex.Message + "\n-> " + ex.StackTrace);
            }
            catch (System.Net.WebException we)
            {
                MessageBox.Show(we.Message + " -> " + we.StackTrace);
            }

the messagebox to display info about the vssDatabase is okay since it opens it without any error. Then it show the messagebox about the current local folder. This is correct as well because I double check it with my VSS.
Then it throws an exception when i try to get items under root......




ASKER CERTIFIED SOLUTION
Avatar of Fittsim
Fittsim

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Fittsim for all your tries.

I just got my problem solved. The problem was that I load in the wrong srcsafe.ini file. The ini file should be on the vss server. I assume it needs to know the location of the file on the server in order to read the directories there. So after having my inipath point to the one on the server, I got it working.

Anyway, thanks again :)
Excellent, I am glad the issue got resolved.  Good luck with the rest of the project, I'm sure Ill be posting on here in the next few weeks how to check in and out files.  lol