I have a raster file for which I know the the workspace, but not the filename (it is a temporary file generated by operations from my program that randomizes its name on creation, i.e. "ras457"). I cannot store the raster at time of generation for various reasons, so is there a way to programatically grab the raster from the folder without knowing its exact name and store it in an IGeoDataset?

The raster is stored in a temporary folder created when I run the program, so it will be the only item in the folder.

One route I have considered exploring is using .NET's directory info class to get the names of the contents of the folder and extracting it from there, but there may be a simpler way to accomplish this that I have not considered.


It seems to me that you could easily add logic to your program that stores the string name of the raster that you create for later usage. If you use a geoprocessor object to create the raster there is usually an option to add the output to the map. If for some reason that is not possible then you can get the name via .NET or ArcObjects. You say there is just one raster put in a temporary dir. Therefore you can simply do something like this with ArcObjects if you have an IWorkspace object named tempWorkspace:

IEnumDataset enumDataset = tempWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset);
IDataset dataset = enumDataset.Next();

or with .NET:

                string[] rasters = Directory.GetFiles(<string path to your workspace>",*.jpg");                      
                foreach (string rasterName in rasters)
  • get_Datasets was the method I was looking for. Thank you.
    – Conor
    Jul 12 '13 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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