0

I am developing a smart device application in windows mobile 6.5 with .NET CF 3.5 using C#. user will use this application to write xml file to storage card, every day around have 5000 xml files to be written to storage card. but there have a problem I can not find the root reason, that is sometimes write the file is zero size and also can not be opened these zero size files.

using (StreamWriter sw = System.IO.File.CreateText(@"\Storage Card\temp\filename01.xml"))
{
     xmldocData.Save(sw);
     sw.Flush();
     sw.Close();
}

I will grateful if anyone can help?

2 Answers2

0

Is it possible that some of the data you are trying to write is empty?

using (StreamWriter sw = System.IO.File.CreateText(@"\Storage Card\temp\filename01.xml"))
{
    if ( sw.BaseStream.Length > 0)
    {
       xmldocData.Save(sw);
    }
    sw.Flush();
    sw.Close();
}

Its a bit hard to tell, are you able to show some more code around the data you are saving?

sa_ddam213
  • 42,848
  • 7
  • 101
  • 110
  • Thank you very much!! '\Storage Card\temp\filename01.xml' is the file name which is not existing before save. so sw.BaseStream.Length is always zero. xmldocData is the XmlDocument Object in momory which include some xml elements e.g. timestamp, deviceid, userid, logdetail etc. – user1985736 Jan 17 '13 at 07:06
  • Xml Data sample: 2012-01-01 12:37:26 xxxxxx x xxxx ??? – user1985736 Jan 17 '13 at 07:07
  • Is it possible the windows mobile storage card has IO buffer and this problem is because of the buffer overflowed? because while I write a file into storage card folder and meanwhile I also write a copy to device internal folder, but the internal file has no zero size cases. if so, how to clear storage card IO buffer – user1985736 Jan 17 '13 at 07:08
  • As you say, you cannot open those zero bytes files, is the app still running? If so, are you using a thread to save those files and the file save crashed? We have also seen faulty memory card drivers, possibly ask support of your device (model?) about new firmware/drivers. You are also saying that the same files are created on the device and have not a zero byte size: is the memory card corrupted (try a reformat). Is it a consumer card? These are not designed for that much of file changes. Better do a zip of the device files at end of day and copy the zip once a day onto the device. – josef Jan 17 '13 at 09:46
0

Possibly a problem with the SD card or the driver.

Please check the SD card. Use different cards of other vendors to test.

Do not save and change too much on a SD card, they are not designed as a hard disk. See wear-leveling etc. Most consumer cards are designed for normal day-by-day use but not for industrial use.

There are much better Industrial Use SD cards for example by ATP with better wear-leveling etc to allow you to change the 'memory' bytes more often.

See the vendor of your device and ask for a new memory card driver or device firmware or there recommended SD cards.

josef
  • 5,951
  • 1
  • 13
  • 24
  • Thank you very much! josef. Your comment is helpful for me. – user1985736 Jan 21 '13 at 03:20
  • I know of one problem, where the thread priority of the saving code had an higher or same prio as the the driver code that tried to follow the changes and write them to the SD card. The result was corrupted files and FAT on the SD card.Normally the driver uses detected idle times to write data back to sd card. But what, if there is no idle time? The sd card gets out of sync. – josef Jan 21 '13 at 05:04