Error when trying to write to a local drive using System.IO.StreamWriter - InfoPath Dev
in

InfoPath Dev

Error when trying to write to a local drive using System.IO.StreamWriter

Last post 02-25-2014 12:23 PM by Silver04. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 02-25-2014 12:23 PM

    Error when trying to write to a local drive using System.IO.StreamWriter

    I currently have a Web Browser form published that in preview, I can use C# to create a .txt file of items in a repeating table and save to a mapped drive. Once published through Central Administration /Fully Trusted, I receive an error message when clicking the button that kicks off the code to access the local drive and write the .txt file to it. Are there any special permission that I have to have turned or do I need pass credentials to allow access to the local drive, which is not protected.

    Here is my code:

    // Setup array for data
                string[] dbsFunctions = new string[tableRows.Count + 1];
                int arrayPosition = 0;
                string dbsID = root.SelectSingleNode("/my:myFields/my:dbsID", NamespaceManager).Value;
                string userFuncNumber = root.SelectSingleNode("/my:myFields/my:userFuncNumber", NamespaceManager).Value;

                // Loop through dbs repeating table and populate array with data
                while (tableRows.MoveNext())
                {
                    string value = tableRows.Current.SelectSingleNode("my:Function_Select", NamespaceManager).Value.ToString();
                    string dbsFunction = tableRows.Current.SelectSingleNode("my:Function_Name", NamespaceManager).Value.ToString();
                    string chkTrue = "True";

                    if (value == chkTrue)
                    {
                        dbsFunctions[arrayPosition] = "R" + dbsID + " " + dbsFunction;
                        arrayPosition += 1;
                    }
                }

                // Generate .txt file for dbs functions update
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"Z:" + userFuncNumber + ".txt"))
                {
                    foreach (string line in dbsFunctions)
                    {

                        file.WriteLine(line);
                    }
                }

Page 1 of 1 (1 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.