How to get path of default scratch workspace(folder) using c#?

I'm making REST GP tool, where you pass some input parameters, tool collects data, create csv files, and archive them. Then tool return path to archive file.

Tool logic is done, but i'm stuck on where to write files(and how to return path), and thought, that scratch folder would be good choice for that. In python I would do something like:




But that doesn't work in C#. Any suggestions?


Thanks, it was really that simple in the end

IScratchWorkspaceFactory scratchWsF = new ScratchWorkspaceFactory();
IWorkspace sWS = scratchWsF.DefaultScratchWorkspace;
string scratchWS = System.IO.Path.GetDirectoryName(sWS.PathName)+"\\";

EDIT 2: The previous solution works fine for GP tool and returns smth like "C:\Users\Admin\AppData\Local\Temp\arc161B...", but for GP REST service that does not work:

IScratchWorkspaceFactory2 scratchWsF = new ScratchWorkspaceFactory() 
    as IScratchWorkspaceFactory2;
IScratchWorkspaceFactory scratchWsF = new ScratchWorkspaceFactory();

stops the execute method, without any error if used in published GP service(but works in GP tool). Recently found out, that every instance of GP service have its own scrach, but i am unable to find a way to get to that.

  • Did you try using activator.createinstance as recommended in the help doc? Nov 16, 2012 at 13:44
  • 1
    I dont see what does it have to do with this case. well i found out how to get scratch workspace of each job instace string scratchWS = envMgr.FindEnvironment("scratchworkspace").Value.GetAsText(); But the problem is that it returns the real addres example: c:\arcgissserver\... but i am also trying to get virtual address /rest/directories/arcgisjobs/... I can see that directory in this service options, but have no idea how to get it from code.
    – Sunder
    Nov 19, 2012 at 9:44

1 Answer 1


Can you use IScratchWorkspaceFactory::DefaultScratchWorkspace or IScratchWorkspaceFactory2::CurrentScratchWorkspace to get the path?

  • Going to look into that.
    – Sunder
    Nov 14, 2012 at 9:39
  • It works for GP tool, but not for published GP service as far as i know/tried.
    – Sunder
    Nov 16, 2012 at 9:16

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.