ICatalogManager3::ImportCSV Method [C++]

Use this method to import a comma-separated values (CSV)-formatted file as catalog data.

Definition

[C++]

HRESULT ICatalogManager3::ImportCSV(BSTRstrCSVFileSource,
  BSTRstrProductIDColumnName,
  BSTRstrPriceColumnName,
  BSTRstrCatalogName,
  VARIANT_BOOLfUpdateOnlyVARIANT_BOOLfRunSynchronouslyBSTRstrLang,
);

[Visual Basic]

Sub ImportCSV(strCSVFileSource As String,
  strProductIDColumnName As String,
  strPriceColumnName As String,
  strCatalogName As String,
  fUpdateOnly As BooleanfRunSynchronously As BooleanOptional strLang As String,
)

Parameters

  • strCSVFileSource[C++]
    [in] A BSTR that contains the path and file name of the CSV file to import.
  • strCSVFileSource[Visual Basic]
    A String that contains the path and file name of the CSV file to import.
  • strProductIDColumnName[C++]
    [in] A BSTR that contains the name of the column that provides a unique ID for products to be imported into the catalog.
  • strProductIDColumnName[Visual Basic]
    A String that contains the name of the column that provides a unique ID for products to be imported into the catalog.
  • strPriceColumnName[C++]
    [in] A BSTR that contains the name of the column in the CSV file containing the product prices.
  • strPriceColumnName[Visual Basic]
    A String that contains the name of the column in the CSV file containing the product prices.
  • strCatalogName[C++]
    [in] A BSTR that contains the name of the catalog into which the CSV file will be imported. The name of the catalog cannot begin with the character "#" or consist solely of spaces. For more information about catalog name restrictions, see Catalog Name and Size Restrictions.
  • strCatalogName[Visual Basic]
    A String that contains the name of the catalog into which the CSV file will be imported. The name of the catalog cannot begin with the character "#" or consist solely of spaces. For more information about catalog name restrictions, see Catalog Name and Size Restrictions.
  • fUpdateOnly[C++]
    [in, defaultvalue (0)] A VARIANT_BOOL that specifies whether to update an existing catalog or create a new one. A value of True indicates that if the system contains a catalog whose name is the same as the one specified in the strCatalogName parameter, it will be updated with the imported data. A value of False indicates to delete the catalog if it already exists and create a new one with the imported data.
  • fUpdateOnly[Visual Basic]
    A Boolean that specifies whether to update an existing catalog or create a new one. A value of True indicates that if the system contains a catalog whose name is the same as the one specified in the strCatalogName parameter, it will be updated with the imported data. A value of False indicates to delete the catalog if it already exists and create a new one with the imported data. The default value is False.
  • fRunSynchronously [C++]
    [in, defaultvalue (0)] A VARIANT_BOOL that specifies whether the method should be run synchronously. A value of True indicates that the method will not return until the import is completed. A value of False indicates that the method will return immediately after spawning the import thread.
  • fRunSynchronously [Visual Basic]
    A Boolean that specifies whether the method should be run synchronously. A value of True indicates that the method will not return until the import is completed. A value of False indicates that the method will return immediately after spawning the import thread. The default value is False.
  • strLang[C++]
    [in, optional, defaultvalue ("")] A BSTR that contains the culture name. The culture name follows the RFC 1766 standard in the format "<languagecode2>-<country/regioncode2>" where <languagecode2> is a lowercase two-letter code derived from ISO 639-1 and <country/regioncode2> is an uppercase two-letter code derived from ISO 3166. Some culture names have prefixes that specify the script; for example, "Cy" specifies the Cyrillic script, and "Lt" specifies the Latin script. For more information, see . Table of Language Culture Names, Culture Codes, and ISO Values.
  • strLang[Visual Basic]
    A String that contains the culture name. The culture name follows the RFC 1766 standard in the format "<languagecode2>-<country/regioncode2>" where <languagecode2> is a lowercase two-letter code derived from ISO 639-1 and <country/regioncode2> is an uppercase two-letter code derived from ISO 3166. Some culture names have prefixes that specify the script; for example, "Cy" specifies the Cyrillic script, and "Lt" specifies the Latin script. For more information, see . Table of Language Culture Names, Culture Codes, and ISO Values.

Return Values

[C++] This method returns an HRESULT indicating whether it completed successfully.

[Visual Basic] None.

Error Values

[C++] This method returns S_OK (0x00000000) to indicate success and either standard or custom COM HRESULT error values to indicate failure. For more information about standard COM errors, see Standard COM Errors.

[Visual Basic] This method sets the Number property of the global Err object to S_OK (&H00000000) to indicate success and to either standard or custom COM error values to indicate failure. For more information about standard COM errors, see Standard COM Errors.

The following table shows the custom COM errors that this method can return.

Name Value Description
E_CAT_CATMGR_NOT_INITIALIZED

[C++] 0x889800B5

[Visual Basic] &H889800B5

The CatalogManager object has not been initialized. The CatalogManager object should be initialized before calling this method.
E_CAT_INVALID_CATALOGNAME

[C++] 0x88980063

[Visual Basic] &H88980063

The Catalog name you specified is invalid. Catalog names cannot be blank.
E_CAT_INVALID_CATALOG_NAME_LENGTH

[C++] 0x88980042

[Visual Basic] &H88980042

The Catalog name you specified exceeds the maximum limit of 85 characters.
E_CAT_CHARACTER_NOT_ALLOWED

[C++] 0x8898003D

[Visual Basic] &H8898003D

The catalog name you specified has one of the nine reserved characters " [ ] , ' ( )#. which should not be used.
E_CAT_INVALID_LANGUAGE

[C++] 0x8898009E

[Visual Basic] &H8898009E

The value you specified for the Language parameter is either empty or exceeds the maximum length of 10 characters.
E_CAT_INVALID_PROPERTY_NAME

[C++] 0x889800A2

[Visual Basic] &H889800A2

The property name you specified is invalid. Property names cannot be blank and cannot exceed 100 characters. Property names cannot begin with a digit and cannot contain one of the following five reserved characters .,"[]
E_CAT_FILE_OPEN_ERROR

[C++] 0x88980020

[Visual Basic] &H88980020

Unable to open the file . Check that the file exists and you have the necessary permissions on the file.
E_CAT_IMPORT_IN_PROGRESS

[C++] 0x88980025

[Visual Basic] &H88980025

This operation cannot be started because an import operation is currently in progress.
E_CAT_CONFLICTING_PRODUCTID

[C++] 0x88980113

[Visual Basic] &H88980113

The ProductID property you specified for this Catalog does not match the existing PrIoductID property. When importing a catalog in the update mode the ProductID property should match the existing ProductID property

[C++] Additional information may be available using the global Err object, which can be accessed using the API function GetErrorInfo. In particular, the GetDescription method of the IErrorInfo interface may return a text description of the error.

[Visual Basic] Additional information may be available using the global Err object. In particular, the Description property may contain a text description of the error.

Remarks

If the parameter strCatalogName specifies a catalog that does not exist, a new catalog will be created and the value of the fUpdateOnly parameter is ignored.

The strLang parameter specifies the language for multilingual properties in the imported catalog. If the strLang parameter is not specified then the default system language of the Web server will be used for multilingual properties.

The ImportCSV method is used to bring existing data from a wide variety of sources into the Product Catalog System. The CSV file must conform to the following format:

  • The first row of data must consist of column names, separated by commas. New lines in the text file delimit Rows.
  • For each column in the heading, a new property of the string data type with a maxlength of 256 will be created if the property does not exist. If the property already exists in the Product Catalog System then the existing property will be used.
  • Each subsequent row (called a data row) must have the same number of commas as the first row. In other words, all columns in the CSV file must be defined by the first row.
  • All items in the CSV file (one row per item) are assumed to be products, and are created from a common product definition. If no product definition exists in the destination catalog, one will be created during the import process.
  • Each item must specify a value for the column specified as the ProductID column, as well as for the column specified as the Price column.
  • Two adjacent commas must represent missing data. If the data itself contains a comma then it must be enclosed in double quotes as in the example of the following 3 data items: weight, "yellow, blue, green or red", name.

This method runs in a separate thread. Prior to spawning the thread, it checks that the specified file can be opened and that there is not an existing ImportCSV or ImportXML method in progress. Once the new thread is spawned, this method returns immediately, if the parameter fRunSynchronously is False, with no errors. Any errors that occurred while importing the catalog are logged to the Windows NT Event Log. Use the Windows Event Viewer to view the Windows NT Event Log.

Ee783906.caution(en-US,CS.20).gifCaution

  • If you call this method from Visual Basic Scripting Edition (VBScript) with the fRunSynchronously parameter set to False, VBScript will unload the object as soon as the script ends. If the script ends before the spawned thread finishes importing the catalog, it will be terminated prematurely and the catalog will not be imported successfully.

This method cannot be called in a transacted object. This method involves the creation, deletion, or updating of free text indexes. SQL Server does not allow these operations in a transaction.

If there is a temporary loss of the SQL Server connection, longer than two minutes, an import or export will be aborted. Other methods should work after the interruption.

For more information about memory ownership issues related to COM property and method parameters, see Managing COM Parameter Memory.

[Visual Basic]

Example

myCatalogManager.ImportCSV "c:\imports\ourcatalog.csv", "SKU", "Price", "OurCatalog", TRUE

See Also

[C++]CatalogManager Object

[Visual Basic]CatalogManager Object

[C++]ICatalogManager3::ExportCSV

[Visual Basic]CatalogManager.ExportCSV

[C++]ICatalogManager3::ImportXML

[Visual Basic]CatalogManager.ImportXML

[C++]Table of Language Culture Names, Codes, and ISO Values

[Visual Basic]Table of Language Culture Names, Codes, and ISO Values

Copyright © 2005 Microsoft Corporation.
All rights reserved.