private void button1_Click(object sender, EventArgs e)
{
try
{
//create raster dataset from the JPIP service url
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
IWorkspaceFactory wsFact = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
string tempPath = Path.GetTempPath();
IRasterWorkspace2 ws = wsFact.OpenFromFile(tempPath, 0) as IRasterWorkspace2;
IRasterDataset rds = ws.OpenRasterDataset(txtJPIPUrl.Text);
//create a layer from the raster dataset
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromDataset(rds);
string layerName = txtLayerName.Text;
if (layerName == "")
layerName = txtJPIPUrl.Text.Substring(txtJPIPUrl.Text.LastIndexOf("/") + 1, txtJPIPUrl.Text.Length - txtJPIPUrl.Text.LastIndexOf("/") - 1);
rasterLayer.Name = layerName;
//add the JPIP layer to the current data frame of ArcMap
ArcMap.Document.FocusMap.AddLayer(rasterLayer);
this.Close();
}
catch
{
MessageBox.Show("Couldn't connect to the specified URL, sample url: jpip://myserver:8080/JP2Server/imagealias");
}
}