IDownloadCmd2::InitializeAttachment

The InitializeAttachment method is called to initialize the Download command, by specifying an object store item to download and providing a destination directory for the saved file on the local machine. The client application indicates which item to download by specifying an IObjectStoreItem whose bstrVersionID parameter is either a GUID or a special version name: release, current, or reservation. The client may also identify which content element to download, by supplying the index value of the element.

The IDownloadCmd2::InitializeAttachment method only requires that you specify the destination directory for the file. The filename is extracted from the HTTP response headers attachment name. However, if you prefer to provide the full pathname for the file, use the IDownloadCmd::Initialize method instead.

NOTE If you would prefer to prompt the user for the filename and path location on their local machine to apply to the downloaded object store item, the client application must invoke the FileSaveAsDlg command before issuing the Download command.

void spIDownloadCmd->InitializeAttachment(_bstr_t bstrDirectoryName,
                                          IObjectStoreItemPtr pIObjectStoreItem,
                                          long contentElementIndex);
Parameters
bstrDirectoryName - [in] Required _bstr_t, which specifies the destination directory on the local machine, to apply to the downloaded object store item.
pIObjectStoreItem - [in] Required pointer to an IObjectStoreItem interface, which specifies the object store item to download via the item version ID parameter, which can be set to the following:


contentElementIndex - [in] Required long integer, which represents the zero-based index value of the desired content element. A value of "0" will download the primary content element.
Results
This method always returns an HRESULT value of S_OK if successful.
Sample
The following is a fragment which demonstrates how to initialize the IDownloadCmd2 interface which is very similar to the IDownloadCmd interface. The Download command section contains a complete example of how to initialize the IDownloadCmd interface.
   ...
   // Instantiate the custom Download command component
   IDownloadCmd2Ptr spIDownloadCmd2;
hResult = spIDownloadCmd2.CreateInstance(__uuidof(DownloadCmd));
if (FAILED(hResult)) {
std::cout << "Could not create the Download command component.\n"; _ASSERTE(0);
} // Instantiate the ObjectStoreItem component IObjectStoreItemPtr pIObjectStoreItem; hResult = spIObjectStoreItem.CreateInstance(__uuidof(ObjectStoreItem));
if (FAILED(hResult)) {
std::cout << "Could not create the ObjectStoreItem component.\n"; _ASSERTE(0);
} // Initialize the ObjectStoreItem component with // the items' type, object store name, version series ID and item ID ItemType eItemType = eItemTypeDocument; _bstr_t bstrObjectStoreName = (_T("Alaska")); _bstr_t bstrVersionSeriesID = (_T("{6BC064A2-2D58-4B0A-AEF2-B2F8A1100000}")); _bstr_t bstrItemID = (_T("release")); std::cout << "Initializing the ObjectStoreItem component..." << std::endl;
spIObjectStoreItem->Initialize(eItemType, bstrObjectStoreName, bstrVersionSeriesID, bstrItemID); // Initialize the custom Download command component // with the destination directory on the local machine, // of the downloaded object store item and optionally, // the index value of the content element to download. _bstr_t bstrDirectoryName = (_T("C:\Downloaded Documents")); long contentElementIndex = 0L; std::cout << "Initializing the Download command component..." << std::endl; spIDownloadCmd2->InitializeAttachment(bstrDirectoryName, spIObjectStoreItem, contentElementIndex); ...