ILayerPtr pLayer <-- provided as calling parameter CString csLyrFileName <-- provided as calling parameter ILayerFilePtr pLayerFile = NULL; IDataLayer2Ptr pDataLayer2 = NULL; HRESULT hr = S_OK; // Create the Layer File object class instance pLayerFile.CreateInstance(CLSID_LayerFile); // QI to the IDataLayer2 interface pDataLayer2 = pLayer; // Set the property that will result in a ".\" entry in the // saved layer file to support relative path capabilities // when re-loading the layer from the *.lyr file. // Testing in conjunction with Esri Incident #928311 shows that // this approach of assigning the full *.lyr file name // into the ->put_RelativeBase() is the technique to achieve the // intended "relative path" behavior. // Note: This whole concept of saving the *.lyr file with relative paths // is only applicable if the *.lyr file is saved into the same directory // as the actual data source (such as the shapefile or the personal geodatabase). // If the *.lyr file is saved into a different directory, then it is not // possible to save a relative path. hr = pDataLayer2->put_RelativeBase(CComBSTR(csLyrFileName)); // Create a new layer file hr = pLayerFile->New(CComBSTR(csLyrFileName)); // Attach the layer file with the actual layer hr = pLayerFile->ReplaceContents(pLayer); // Save the layer file hr = pLayerFile->Save();