如何打开一个文件,而不是下载到我的电脑

本文关键字:下载 电脑 我的 文件 何打开 一个 | 更新日期: 2023-09-27 18:16:23

我只是想打开上传到我的gridview的文件,而不下载它。但是当我试图打开它的时候,它给了我一个错误,叫做非法路径。任何想法。

    private void cncInfoDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        //Throw error if attachment cell is not selected.
        //make sure user select only single cell
        //and the cell have a value in it
        if (SelectedNonNullCellFromColumn(1))
        {
           OpenAttachment(cncInfoDataGridView.SelectedCells[0]);
        }
     }

  private void OpenAttachment(DataGridViewCell dgvCell)
    {
        if (SelectedNonNullCellFromColumn(1))
        {
            using (OpenFileDialog fileDialog = new OpenFileDialog())
            {
                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    string strfilename = fileDialog.FileName;  // gets the path
                    string result;                              //initilizate the filename variable
                    result = Path.GetFileName(strfilename);
                    //string strfilename = File.ReadAllText("");
                    cncInfoDataGridView.Rows[dgvCell.RowIndex].Cells[5].Value = strfilename;
                    using (var fileStream = new FileStream(strfilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var textReader = new StreamReader(fileStream))
                    {
                        var content = textReader.ReadToEnd();
                    }
                }
            }
        }
    }

如何打开一个文件,而不是下载到我的电脑

我找到了答案。谢谢大家…

private void OpenAttachment(DataGridViewCell dgvCell)
    {
        if (SelectedNonNullCellFromColumn(1))
        {
            string s = cncInfoDataGridView.Rows[dgvCell.RowIndex].Cells[5].Value.ToString(); // stores in string s
            System.Diagnostics.Process.Start(s);   ///Open the file
        }
     }