首页 > 解决方案 > How to store C# SpecialFolder path into SQLite database?

问题描述

I am working on a WPF app and I am stuck in a tricky problem.

There is a TEXT field called "OutputFolder" into SQLite database which stores different folder paths (as name suggests its folder where some output is generated).

I want to save special folder path (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) into SQLite database in "OutputFolder".

Actual value I want to store in database

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\temp";

I have no option to use any other directory or something else. Its very clear that I have to store this path into database.

I am open to add new column to specify any flag value or anything that identify path as special folder.

标签: c#wpfsqlite

解决方案


据我了解 - 您需要存储两种类型的绝对路径和一种包含特殊文件夹的路径。问题是如何识别一种路径,然后相应地处理它。

如果您无法更改 db 数据结构(添加其他字段),那么可能是将有关特殊文件夹的信息注入路径的一种方法。

例如,您可以使用无效(用于路径)字符来标记注入的开始和结束。您的路径应如下所示:

var injectedPath = "?5?\\temp";

当然,在阅读时,您必须进行解析,如果发现注入,则将其替换为真实路径。在我们的例子中 MyDocuments = 5 参见Environment.SpecialFolder


推荐阅读