C# 如何在独立的存储文件中存储和检索数据?
我需要存储和检索独立存储文件中的数据。我将从Winforms应用程序中存储数据,但我需要从ASP.NET应用程序中的文件中检索数据。我已通过Winforms应用程序成功地将数据保存在独立文件中。以下是代码C# 如何在独立的存储文件中存储和检索数据?,c#,.net,winforms,C#,.net,Winforms,我需要存储和检索独立存储文件中的数据。我将从Winforms应用程序中存储数据,但我需要从ASP.NET应用程序中的文件中检索数据。我已通过Winforms应用程序成功地将数据保存在独立文件中。以下是代码 IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForDomain(); string[] fileNames = isoStore.GetFileNames(fil
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForDomain();
string[] fileNames = isoStore.GetFileNames(fileName);
if (fileNames != null && fileNames.Length > 0)
{
foreach (string file in fileNames)
{
if (file == fileName)
{
isSuccess = true;
break;
}
else
isSuccess = false;
}
}
if (!isSuccess)
{
oStream = new IsolatedStorageFileStream(fileName, FileMode.Create, isoStore);
writer = new StreamWriter(oStream);
writer.WriteLine(licenseCode);
writer.Close();
}
在ASP.NET应用程序中,我将从隔离存储文件中检索数据。代码如下所示
IsolatedStorageFile isoStore=IsolatedStorageFile.GetUserStoreForDomain()
但是我无法从ASP.NET应用程序(字符串[]fileNames=isoStore.GetFileNames(文件名);此字符串[]返回0)检索存储在独立存储文件中的数据,这表示计算机中不存在任何文件
有人能帮我解决这个问题吗?隔离存储是隔离的(正如名称所示)。因此,您将无法访问来自不同程序集的独立存储。我假设你的ASP.NET应用程序与你的Winform应用程序不在同一程序集中是的,你是对的,两者都是不同的项目,那么我如何从ASP.NET应用程序中的独立存储文件中检索数据?@Ramalingam:正如fix_likes_编码已经说明的那样,独立存储是独立的,因此你无法从不同的应用程序中访问它。
string[] fileNames = isoStore.GetFileNames(fileName);
//Retrieve License Code from Isolated storage
iStream = new IsolatedStorageFileStream(fileName, FileMode.Open, isoStore);
reader = new StreamReader(iStream);
String line;
while ((line = reader.ReadLine()) != null)
{
output = line;
}
return output;