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.

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:

%scratchFolder%\....

or

arcpy.env.scratchFolder

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

EDIT:

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;
//and
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.

share|improve this question
    
Did you try using activator.createinstance as recommended in the help doc? –  Kirk Kuykendall Nov 16 '12 at 13:44
    
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 '12 at 9:44

1 Answer 1

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

share|improve this answer
    
Going to look into that. –  Sunder Nov 14 '12 at 9:39
    
It works for GP tool, but not for published GP service as far as i know/tried. –  Sunder Nov 16 '12 at 9:16

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.