[Network FileSystem] Method File_WriteTextLines not working

[Network FileSystem] Method File_WriteTextLines not working

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

When I use the method File_WriteTextLines, the extension creates the file, but no lines are written.

If I use the File_WriteText everything works, using the same parameters authentication parameters.

Cheers

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);
            }
               
        }