I am using cutom actions to modify a .csv file. Please see the code for the
same below.

<Binary Id='CustomAction.CA.dll'
SourceFile='D:\POC\CustomAction\bin\Debug\CustomAction.CA.dll'/>
    <Property Id="OLDENVIRONMENTVALUE" Value="abcdef"/>
    <Property Id="NEWENVIRONMENTVALUE" Value="xyzedf"/>
    <Property Id="FILEPATH" Value="[INSTALLDIR]MyApp\bin\Test.csv" />

    <CustomAction Id="MyAction.SetProperty"
                  Return="check"
                  Property="CustomAction.CA" 
                  Impersonate="no"
                 
Value="[OLDENVIRONMENTVALUE],[NEWENVIRONMENTVALUE],[FILEPATH]" />

    <CustomAction Id='CustomAction.CA' 
                  BinaryKey='CustomAction.CA.dll' 
                  DllEntry='UpdateCSVFile' 
                  Return="check" 
                  Impersonate="no"
                  Execute='deferred'/>

    <InstallExecuteSequence>
      <Custom Action='MyAction.SetProperty' After='InstallFiles'/>
      <Custom Action='CustomAction.CA' After='MyAction.SetProperty'/>
    </InstallExecuteSequence>    


        [CustomAction]
        public static ActionResult UpdateCSVFile(Session session)
        {

                string[] arguments = GetCustomActionDataArguments(session);
                argument_0 = arguments[0];
                argument_1 = arguments[1];
                argument_2 = arguments[2];

    string[] csvFile = File.ReadAllLines(argument_2);
                    for (int i = 0; i < csvFile.Length; i++)
                    {
                        string line = csvFile[i];
                        line = line.Replace(argument_0, argument_1);
                        if (!csvFile[i].Equals(line))
                        {
                            csvFile[i] = line;
                        }
                    }

                    session.Log("Update the CSV file");
                    using (StreamWriter sWriter = new
StreamWriter(argument_2))
                    {
                        for (int i = 0; i < csvFile.Length; i++)
                        {
                            sWriter.WriteLine(csvFile[i]);
                        }
                    }
           return ActionResult.Success;
     }

        private static string[] GetCustomActionDataArguments(Session
session)
        {
            string[] keys = new string[session.CustomActionData.Keys.Count];
            session.CustomActionData.Keys.CopyTo(keys, 0);
            return keys[0].Split(',');
        }

While defining the property FILEPATH, if I specify the harcoded path of the
file, the above code works fine. Instead of it, if I specify the value of
FILEPATH property as "[INSTALLDIR]MyApp\bin\Test.csv", I get the following
error.

Error:
Could not find a part of the path
'C:\Windows\Installer\MSI32BC.tmp-\C:\Program Files\Bing
SingleBox\MyApp\bin\Test.csv'.

I have verified the path in the CustomAction.CA.dll and it is correct. I am
unable to figure out the issue. Please let me know in case I am doing
anything wrong. Or any pointers to solving this issue will be highly
appreciated.

Thanks and Regards,
Kshama
-- 
View this message in context: 
http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/WIX-tp5121025p5121025.html
Sent from the wix-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------

_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to