![](/img/trans.png)
[英]Run a File, located in Program Files (x86) from PowerShell
[英]How to write in a json file located into the Program files (x86) installation folder winform application?
早上好朋友,我想將數據表保存在json中,原因是我使用了從json文件到xtraReport的數據,后者是json文件。 當我在Visual Studio 2015中運行時,它也加載了它,甚至當我轉到調試文件夾時也是如此。 但是,當我使用installshield 2015限量版創建安裝時(我在安裝程序中添加了文件),我將其安裝,並將應用程序的文件夾創建到Program Files(x86)路徑中。 當我運行winform應用程序時,它無法讀取json文件。 我發現的唯一解決方案是以管理員用戶身份執行Winform應用程序。 這是我的代碼:
public FrmDocBien()
{
InitializeComponent();
dt = new DataTable();
dt.Clear();
dt.Columns.Add("IDB");
dt.Columns.Add("DATEB");
dt.Columns.Add("BARCODE");
}
public void DataTableToJSONWithStringBuilder(DataTable table)
{
var JSONString = new StringBuilder();
if (table.Rows.Count > 0)
{
JSONString.Append("[");
for (int i = 0; i < table.Rows.Count; i++)
{
JSONString.Append("{");
for (int j = 0; j < table.Columns.Count; j++)
{
if (j < table.Columns.Count - 1)
{
JSONString.Append("\"" + table.Columns[j].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][j].ToString() + "\",");
}
else if (j == table.Columns.Count - 1)
{
JSONString.Append("\"" + table.Columns[j].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][j].ToString() + "\"");
}
}
if (i == table.Rows.Count - 1)
{
JSONString.Append("}");
}
else
{
JSONString.Append("},");
}
}
JSONString.Append("]");
}
System.IO.File.WriteAllText((Application.StartupPath + "\\dataBar.json").Replace("\\bin\\Debug", ""), JSONString.ToString());
}
private void btnLoadxtraReport_Click_1(object sender, EventArgs e)
{
this.DataTableToJSONWithStringBuilder(dt);
rpBar = new xrDemo();
rpBar.CreateDocument();
pt = new ReportPrintTool(rpBar);
pt.ShowPreview();
}
工作時(以管理員身份運行): 當獲得有關拒絕訪問的異常(沒有特定用戶的情況下運行)
我會感謝您的幫助。 提前致謝。
如果dataBar.json文件需要由多個用戶共享,最好將其安裝到C:\\ ProgramData \\ SolBienes \\ Datos \\ dataBar.json。 InstallShield應該顯示一個名為“所有用戶程序數據”的文件夾或類似於目標的文件夾,並允許您設置該文件的NTFS權限。
在C#中,您將使用類似以下內容的文件:
string dataBarFilePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"SolBienes\Datos\dataBar.json"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.