简体   繁体   中英

StreamWriter fails to recognize c:\ in compact .net 2.0

I have the following code

        using (var str = new StreamWriter(newFileName))
        {
            foreach (Entry entry in this.Entries)
            {
                str.WriteLine(
                    String.Format(
                        @"""{0}"";{1:yyyy-dd-MMThh:mm:ss};""none"""
                        , entry.Data
                        , entry.Date
                    )
                );
            }
        }

where newFileName = @"C:\\asln.csv"

This codes works fine on .Net Framework 2.0 but fails miserably on Compact 2.0.

It throws an error "Could not find a part of the path '\\\\C:\\\\asln.csv'."

So, for some reason the path is perpended with \\\\ .
How to work around that?

c:\\ does not exist in compact framework (windows ce). All paths need to start with a backslash (\\)

So if it is in the root folder the path should be \\asln.csv. But make sure that the file is actually in the root. Different devices have different rules, and putting the file in the root is probably not going to work on all devices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM