[Network FileSystem] Error on Method "MssFile_WriteTextLines"

[Network FileSystem] Error on Method "MssFile_WriteTextLines"

  
Forge Component
(5)
Published on 2009-03-17 by Matthias Preuter
5 votes
Published on 2009-03-17 by Matthias Preuter

The variable "RLLineRecordList ssLines" is always initialized at the beginning.
Therefore, we will never got write lines in the file.

Sugestion:

public void MssFile_WriteTextLines (RLLineRecordList ssLines, string ssPath, string ssEncoding, string ssDomain, string ssUsername, string ssPassword, out string ssError_message)
{
IntPtr admin_token = IntPtr.Zero;
            ssError_message = "";
           
            try
            {
                if (LogonUser(ssUsername, ssDomain, ssPassword, 9, 0, out admin_token) != 0)
                {
                    ImpersonateLoggedOnUser(admin_token);

if ( !Directory.Exists(Path.GetDirectoryName(ssPath)))
Directory.CreateDirectory(Path.GetDirectoryName(ssPath));
FileStream newFile = File.Open (ssPath, FileMode.Create, FileAccess.Write, FileShare.None);
Encoding encoding = (ssEncoding == "" || ssEncoding == "Default"? Encoding.Default : Encoding.GetEncoding(ssEncoding));
StreamWriter writer = new StreamWriter (newFile, encoding);

ssLines.StartIteration ();
while ( ! ssLines.Eof )
{
writer.WriteLine (ssLines.CurrentRec.ssSTLine.ssText);
ssLines.Advance ();
}

ssLines.EndIteration ();

writer.Close ();
newFile.Close ();

                }
                else
                {
                    ssError_message += "Operation Failed";
                }
            }
            catch (System.Exception se)
            {
                int ret = Marshal.GetLastWin32Error();
                ssError_message += "Win32Error: " + ret + "\n";
                ssError_message += se.ToString();
            }
            finally
            {
                if (admin_token != IntPtr.Zero)
                    CloseHandle(admin_token);
            }
               
        }