How to publish many mxd files in ArcGIS Server 10.1 automatically?
I have about 60 mxd files and I want to publish them automatically. Is there any way to do this?
How to publish many mxd files in ArcGIS Server 10.1 automatically?
I have about 60 mxd files and I want to publish them automatically. Is there any way to do this?
you can use arcpy for publishing your mxd files.
for listing your mxd files use os.walk :
import os
import arcpy
path= r"c:\path"
for (path, dirs, files) in os.walk(path):
for fl in files:
if fl.lower().endswith(".mxd"):
mxd = arcpy.mapping.MapDocument(os.path.join(path, fl))
print mxd.filePath
and then go this way:
1. AnalyzeForMSD() function (info): Analyzes map documents (.mxd) to determine sources for potential suitability and performance issues when converting a map to a map service definition (MSD) file.
Example:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\ReadyForMSD.mxd")
analysis = arcpy.mapping.AnalyzeForMSD(mxd)
2. ConvertToMSD() function (info) : Converts a map to a map service definition (MSD) file.
Example:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\ReadyForMSD.mxd")
msd = r"C:\Project\Output\Project.msd"
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
arcpy.mapping.ConvertToMSD(mxd, msd, df, "NORMAL", "NORMAL")
del mxd, msd
3. PublishMSDToServer() function (info) : Publishes an existing map service definition (MSD) file to a designated ArcGIS Server.
Example:
import arcpy
msd = r"C:\Project\Project.msd"
arcpy.mapping.PublishMSDToServer (msd, "http://<MyServer>/arcgis/services",
"<MyServer>", "MyMapService", "MyMapServiceFolder", ["WMS", "KML"])
the last thing is you should do that merge all funcitons for your needs. actually there is a tutorial which can help u here about Use ArcPy Mapping to Publish Map Documents to ArcGIS Server. it is similar to my documentation...
To summarize(image is from link which i give above):
i hope it helps you...
arcpy.mapping.CreateMapSDDraft
-> arcpy.StageService_server
-> arcpy.UploadServiceDefinition_server
if you want do it in c# you can see in my blog: http://nicogis.blogspot.it/2012/10/ags-101-restful-administrative-api.html
for conversion mxd -> msd you can use python called from c#
Aragon has a great answer, but unfortunately it doesn't work for ArcGIS / ArcServer 10.1.
The new method I just tried is based off of the ArcGIS 10.1 help. You can find the link to the help file here: http://resources.arcgis.com/en/help/main/10.1/index.html#//00s30000006q000000
Here is how I used the code to publish MXDs based on a specified folder:
#import modules
import arcpy, sys, os, string
#specify folder containing MXDs
inFolder = raw_input("Please enter folder containing 10.1 MXDs to Publish to ArcServer: ")
#specify connection File Path
connectionFilePath = r'C:\Users\<your user name>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\<your connection file location.ags>'
#look in folder for mxds
MapPath= []
MapFolder = os.listdir(inFolder)
for file in MapFolder:
fileExt = os.path.splitext(file)[1]
if fileExt == ".mxd":
MapPath = os.path.join(inFolder, file)
file = MapPath.strip('\'')
mxd = arcpy.mapping.MapDocument(file)
base = os.path.basename(file)
serviceName = base[:-4]
SDDraft = file[:-4] + ".sddraft"
sd = file[:-4] + ".sd"
#Create Map SD Draft
print "\n" + "Publishing: " + base
analysis = arcpy.mapping.CreateMapSDDraft(mxd, SDDraft, serviceName, "FROM_CONNECTION_FILE", connectionFilePath, "False", <Service Folder Name>, "None", "None")
# stage and upload the service if the sddraft analysis did not contain errors
if analysis['errors'] == {}:
# Execute StageService
print "Staging Service"
arcpy.StageService_server(SDDraft, sd)
# Execute UploadServiceDefinition
print "Uploading Service Definition"
arcpy.UploadServiceDefinition_server(sd, connectionFilePath)
print "Publishing " + base +" succeeded" + "\n"
else:
# if the sddraft analysis contained errors, display them
print analysis['errors']
There might be a simpler way to use this code, but it works for me. Hope this helps.