Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My implementation of IDataset.Copy continues to crash and I cannot figure out why. The program attempts to copy a shapefile from a temporary folder in one directory to a final folder in another directory. Here is the relevant code, where strOutVoronoiPath is a filepath containing the destination folder and g_temporary is a filepath containing the temporary folder:

        //create a shapefile workspace factory
        ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pSWSF = new ShapefileWorkspaceFactoryClass();

        //create a temporary IWorkspace from Shapefile IWorkspaceFactory object
        ESRI.ArcGIS.Geodatabase.IWorkspace pTempWSP;
        pTempWSP = pSWSF.OpenFromFile(g_tempFolder, 0);            

        //create a final IWorkspace from Shapefile IWorkspaceFactory object
        ESRI.ArcGIS.Geodatabase.IWorkspace pFinalWSP;
        pFinalWSP = pSWSF.OpenFromFile(strOutVoronoiPath, 0);

        //create a temporary IFeatureWorkspace from Shapefile IWorkspaceFactory object
        ESRI.ArcGIS.Geodatabase.IFeatureWorkspace pTempFWS;
        pTempFWS = (IFeatureWorkspace)pSWSF.OpenFromFile(g_tempFolder, 0);

        //create a final IFeatureWorkspace from Shapefile IWorkspaceFactory object
        ESRI.ArcGIS.Geodatabase.IFeatureWorkspace pFinalFWS;
        pFinalFWS = (IFeatureWorkspace)pSWSF.OpenFromFile(strOutVoronoiPath, 0);

        //Some code goes here where I do some casting and operations
        //to produce a shapefile inside the temporary folder. I now have
        //a shapefile I want in temporary folder (at g_tempfolder, which is a string 
        //filepath) and I want to copy it over to a final folder at strOutVoronoiPath
        //I have taken this shapefile and stored the data from it inside an IFeatureClass.
        //called pFeatureClass. The following code attempts to take the feature class data and 
        //cast it into IDataset, from which I call IDataset.Copy. The program crashes 
        //on the final line, where I invoke the pDs.Copy() method.

         pFeatureClass.FeatureClass = pTempFWS.OpenFeatureClass(strOutVoronoiFile);
         pDs = (IDataset)pFeatureClass; //cast the feature class into a dataset
         pDs.Copy(strOutVoronoiFile, (IWorkspace)pFinalFWS);

I'm thinking I might have cast something wrong in the final three lines of code?

share|improve this question
    
Are you sure your program crashes while run pDs.Copy method or it crashes when you cast your feature class into IDataset? –  Emi May 5 '13 at 3:32
    
I am absolutely sure it crashes while running pDs.Copy method. The code successfully casts the feature. –  Conor May 5 '13 at 16:35
    
Your code should check if pFeatureClass is Nothing before you cast it into pDS as that code may be failing, you've not shown us what strOutVoronoiFile is so this may be an invalid file name... –  Hornbydd May 5 '13 at 20:30
add comment

1 Answer 1

I think you should check can you copy this dataset or not. Try this:

     pDs = pFeatureClass.FeatureDataset; 
     if(pDs.CanCopy )
         pDs.Copy(strOutVoronoiFile, (IWorkspace)pFinalFWS);

For details about CanCopy property, follow this.

share|improve this answer
    
I still have not figured this out but I was able to achieve my goals using another method called ConvertFeatureClass that this gentleman wrote detailing here: techblog.alkumait.net/index.php/2011/06/… –  Conor May 5 '13 at 17:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.