Posted by: R Manimaran | August 28, 2008

Crystal Report Server operations using .net SDK

Crystal Report Server operations using .net SDK

 

  • Get Folder ID from Crystal Report Server using .net sdk

 

public static int GetFolderID(InfoStore infoStore, string folderName)

{

string Query = “Select SI_ID FROM CI_INFOOBJECTS WHERE

SI_KIND=’Folder’ and SI_Name='” + folderName + “‘”;

InfoObjects infoObjects = infoStore.Query(Query);

      if (infoObjects.Count > 0)

      {

            InfoObject infoObject = infoObjects[1];

            int folderId = infoObject.ID;

            return folderId;

       }

       else

       {

       return -1;

       //throw new Exception(“NO MATCHES FOUND”);

       }

 }

 

  • Get Folder ID from Crystal Report Server  under a Parent  folder

 

public static int GetFolderID(InfoStore infoStore, string folderName, int ParentFolderID)

 {

 string Query = “Select SI_ID FROM CI_INFOOBJECTS WHERE

     SI_KIND=’Folder’ and SI_Name='” +

                 folderName + “‘ AND SI_PARENTID=” + ParentFolderID;

 

      InfoObjects infoObjects = infoStore.Query(Query);

      if (infoObjects.Count > 0)

      {

            InfoObject infoObject = infoObjects[1];

      int folderId = infoObject.ID;

            return folderId;

      }

      else

      {

      return -1;

                //throw new Exception(“NO MATCHES FOUND”);

      }

  }

 

  • Add a Repoort to the CMS –Crystal Report Server using .net sdk

 

public static void AddReport(InfoStore infostore, string reportName)

{

InfoObjects infoObjects = infostore.NewInfoObjectCollection();

      PluginManager pluginManager = infostore.PluginManager;

      PluginInfo pluginInfo =

pluginManager.GetPluginInfo(“CrystalEnterprise.Report”);

      InfoObject infoObject = infoObjects.Add(pluginInfo);

      Report report = new Report(infoObject.PluginInterface);

report.Files.Add(reportName);//error

      report.Properties.Add(“SI_PARENTID”, folderId);

      report.EnableThumbnail = true;

      report.NeedsLogon = true;

      report.KeepSavedData = true;

//Store the file name as Description

      FileInfo fileinfo = new FileInfo(filename);

      report.Description = fileinfo.Name;

      for (int i = 1; i <= report.ReportLogons.Count; i++)

      {

            report.ReportLogons[i].CustomUserName = “<username>”;

      report.ReportLogons[i].CustomPassword = “<passport>”;

            report.ReportLogons[i].CustomDatabaseName = “<database>”;

      report.ReportLogons[i].UserName = “<username-value>”;

      report.ReportLogons[i].Password = “<password-value>”;

            report.ReportLogons[i].PromptOnDemandViewing = false;

      }

infostore.Commit(infoObjects);

}

 

 

  • Add a Folder to the Crystal Report Server using .net sdk

 

public static int AddFolder(InfoStore infoStore, int parentFolderID,

string FolderName, string FolderDescription)

{

int folderID = -1;

      try

      {

      InfoObjects infoObjects = infoStore.NewInfoObjectCollection();

      PluginManager pluginManager = infoStore.PluginManager;

      PluginInfo pluginInfo =

pluginManager.GetPluginInfo(“CrystalEnterprise.Folder”);

      InfoObject infoObject = infoObjects.Add(pluginInfo);

      Folder folder = new Folder(infoObject.PluginInterface);

      folder.Title = FolderName;

      folder.Description = FolderDescription;

      folder.Properties.Add(“SI_PARENTID”, parentFolderID);

      folderID = folder.ID;

      infoStore.Commit(infoObjects);

      return folderID;

      }

      catch (Exception ex)

      {

            if (ex.Message.ToString().Contains(“Duplicate”))

      {

      folderID = GetFolderID(infoStore, FolderName,

parentFolderID);

      return folderID;

      }

            else

Log.WriteFile(“Error adding folder to Crystal Report

Server. Message:” +

ex.Message,Log.LogFileType.ERROR);

      }

}

            return folderID;

        }

 

  • Delete Folder in the Crystal Report Server using .net SDK

 

private static void DeleteFolder(InfoStore infoStore, int

parentFolderID, string FolderName)

{

try

      {

      string Query = “Select SI_ID FROM CI_INFOOBJECTS WHERE

    SI_KIND=’Folder’ and SI_Name='” +

                      FolderName + “‘ AND SI_PARENTID=” +

    parentFolderID;

       InfoObjects infoObjects = infoStore.Query(Query);

       if (infoObjects.Count > 0)

       {

            InfoObject infoObject = infoObjects[1];

            int folderId = infoObject.ID;

            infoObject.DeleteNow();

            Log.WriteFile(“Deleting the Folder :” + FolderName + ” in

Crystal Report Server”, Log.LogFileType.INFO);

        }

        else

        {

            // return -1;

            //throw new Exception(“NO MATCHES FOUND”);

            Log.WriteFile(“No folder of name “ + FolderName + ” found

in Crystal Report Server”, Log.LogFileType.INFO);

         }

       }

       catch (Exception ex)

       {

       throw new ApplicationException(“Error Deleting Product Folder:”

+ FolderName +                                                ” from Crystal Report Server. Message:”+ex.Message);

        }

 }

 

  • Move a Object from one folder to another folder in Crystal Report Server using .net SDK

 

private static void MoveObjects(InfoStore infoStore, int

ObjectFolderID, int parentFolderID, int newFolderID)

 {

      try

      {

            string Query = “Select SI_ID FROM CI_INFOOBJECTS WHERE

    SI_KIND=’Folder’ and SI_ID=” +

    ObjectFolderID + ” AND SI_PARENTID=” +

     parentFolderID;

InfoObjects infoObjects = infoStore.Query(Query);

            if (infoObjects.Count > 0)

            {

                  InfoObject infoObject = infoObjects[1];

 

                    int folderId = infoObject.ID;

                    //infoObject.DeleteNow();

                    Folder folder = new

   Folder(infoObject.PluginInterface);

                    folder.Properties.Add(“SI_PARENTID”, newFolderID);

                    int folderID = folder.ID;

                    infoStore.Commit(infoObjects);

                    //int cnt = infoObject.Files.Count;

                    //return folderId;

                }

                else

                {

                    // return -1;

                    //throw new Exception(“NO MATCHES FOUND”);

                }

            }

            catch (Exception ex)

            {

                throw new ApplicationException(“Error moving Folder in

    Crystal Report Server. Message:”+ex.Message);

            }

 

        }

Advertisements

Responses

  1. i would like to pass report id to business objects infoview use
    Response.Redirect(“http://” & cmsName & “:” & Port & “/businessobjects/enterprise115/desktoplaunch/InfoView/logon/logon.do?token=” & LogonTokenMgr
    use asp.net
    please help me

  2. Thanks for your solution, it work !!!. I can successfully upload a report to CE However, I have a question on update an existing report in CE. is that a way to do with .net sdk? Thanks.

    Do you have an sample to get a Report from CE with .net sdk and generate to PDF doc?

  3. Thanks maran.. its very helpful

  4. I am trying to add a crystal report template (*.rpt) using your AddReport method but I am unable to see the database parameters in CMC app after loading. Also I don’t have the ability to schedule the report in CMC by right clicking.

  5. This has been very helpful for me. Thanks!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: