?
Solved

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

Posted on 2006-05-19
7
Medium Priority
?
877 Views
Last Modified: 2009-07-29
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.
0
Comment
Question by:thdm1907
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:Fittsim
ID: 16737914
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.
0
 

Author Comment

by:thdm1907
ID: 16738035
Thank you for your help, I really appreciate it :)

I did try both ways but it still doesn't solve my problem.
0
 
LVL 1

Expert Comment

by:Fittsim
ID: 16738135
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).


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:thdm1907
ID: 16738417

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......




0
 
LVL 1

Accepted Solution

by:
Fittsim earned 2000 total points
ID: 16738646
Alright I was able to get it to work fine for me using this

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using Microsoft.VisualStudio.SourceSafe.Interop;


namespace dBTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Foo()
        {
            VSSDatabase myVss = new VSSDatabase();
            myVss.Open(@"C:\Projects\dBTest\srcsafe.ini", "Admin", "password");

            VSSItem vssRoot = myVss.get_VSSItem("$//", false);

            IVSSItems items = vssRoot.get_Items(false);
            foreach (VSSItem itm in items)
            {
                MessageBox.Show(itm.Spec);
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            Foo();
        }
    }
}
0
 

Author Comment

by:thdm1907
ID: 16743653
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 :)
0
 
LVL 1

Expert Comment

by:Fittsim
ID: 16743673
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
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question