2

Can I create a Workspace without using IWorkspaceFactory.Create

I am trying to create a Workspace without specifying it's parent directory, is that possible ?

2 Answers 2

3

Use a ScratchWorkspace. They are basically temporary local GeoDatabases that have full (single-user) GDB functionality. To create them, you don't need to specify anything. After you release the last reference, they get deleted.

2
  • 1
    Thanks for the reply, but Scratch Workspaces were designed to be created and used within a single session. If an application is started again at a later time, there is no reliable method for retrieving data that was previously stored in a ScratchWorkspace.
    – Seem
    Commented Apr 2, 2013 at 9:58
  • 1
    I guess if you do want it to be permanent, where do you want it to live (since wanting them to be permanent means that you want to access it again)? One option is to get the current user directory stackoverflow.com/questions/1140383/… and then generate a unique file name stackoverflow.com/questions/1602578/… . Append those two things and pass them to the IWorkspaceFactory.Create and you will have a permanent unique workspace Commented Apr 2, 2013 at 17:56
1

I am not sure if it is possible not to use the .Create method, but i can giveyou an advice:

try to use the InMemoryWorkSpaceFactory:

/// <summary>
    /// Creates a workspace that resides in memory
    /// </summary>
    /// <returns>A feature workspace</returns>
    public static IFeatureWorkspace GetFeatureWorkspace()
    {
        InMemoryWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
        IWorkspaceName workspaceName = workspaceFactory.Create(string.Empty, "Workspace", null, 0);

        IName name = (IName)workspaceName;
        IWorkspace inmemWor = (IWorkspace)name.Open();

        return (IFeatureWorkspace)inmemWor;
    }

This kind of workspace does not require a path; but a withdraw is that has limited functionality in version 10 i.e: I was not able to update features created by a locator, in other hand in version 9.x it was possible.

1
  • Thanks a lot for you reply, as you can see InMemoryWorkSpaceFactory is used to create a temporary workspace that is stored in memory. So if I wanted to user the created Workspace again after releasing all of it's references, it will not be possible.
    – Seem
    Commented Apr 2, 2013 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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