简体   繁体   English

StreamWriter无法在紧凑的.net 2.0中识别c:\\

[英]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" 其中newFileName = @"C:\\asln.csv"

This codes works fine on .Net Framework 2.0 but fails miserably on Compact 2.0. 该代码在.Net Framework 2.0上工作正常,但在Compact 2.0上却失败。

It throws an error "Could not find a part of the path '\\\\C:\\\\asln.csv'." 它将引发错误"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). c:\\在紧凑框架(windows ce)中不存在。 All paths need to start with a backslash (\\) 所有路径都必须以反斜杠(\\)开头

So if it is in the root folder the path should be \\asln.csv. 因此,如果它在根文件夹中,则路径应为\\ 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. 不同的设备有不同的规则,将文件放在根目录中可能无法在所有设备上正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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