系统为vs2005,前台代码为:
<tr style="height:10px;">
<td align="right" style="width:150px;height:10px;">附件:</td>
<td align="left" colspan="2" style="height: 21px;">
原始电子文档存放路径地址:<br />
<input id="File" style="width: 589px" type="file" runat="server" class="InputCss" /></td>
</tr>
后台代码为:
//将附件传送到服务器上
string str = this.File.PostedFile.FileName;
string ss = str.Substring(str.LastIndexOf("\\") + 1);
string s = Server.MapPath("..\\htfiles\\" + ss);
path = "..\\htfiles\\" + ss;
这中间有一个insert into 语句将该文件路径path存入到数据库中
if (str == string.Empty) return;
this.File.PostedFile.SaveAs(s);
请问:如何打开该路径的文件呢?(文件类型为:word,execl,txt,pdf等),请给出完整的前台和后台代码。
<tr style="height:10px;">
<td align="right" style="width:150px;height:10px;">附件:</td>
<td align="left" colspan="2" style="height: 21px;">
原始电子文档存放路径地址:<br />
<input id="File" style="width: 589px" type="file" runat="server" class="InputCss" /></td>
</tr>
后台代码为:
//将附件传送到服务器上
string str = this.File.PostedFile.FileName;
string ss = str.Substring(str.LastIndexOf("\\") + 1);
string s = Server.MapPath("..\\htfiles\\" + ss);
path = "..\\htfiles\\" + ss;
这中间有一个insert into 语句将该文件路径path存入到数据库中
if (str == string.Empty) return;
this.File.PostedFile.SaveAs(s);
请问:如何打开该路径的文件呢?(文件类型为:word,execl,txt,pdf等),请给出完整的前台和后台代码。
2.using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
3. 这是自定义函数,然后调用
public bool ExportDataGridview(DataGridView gridView, bool isShowExcle)
{ if (gridView.Rows.Count == 0) return false; //建立Excel对象
Excel.Application excel = new Excel.Application(); excel.Application.Workbooks.Add(true); excel.Visible = isShowExcle; //生成字段名称 for (int i = 0; i < gridView.ColumnCount; i++)
{ excel.Cells[1, i + 1] = gridView.Columns[i].HeaderText; } //填充数据 for (int i = 0; i < gridView.RowCount - 1; i++)
{ for (int j = 0; j < gridView.ColumnCount; j++)
{ if (gridView[j, i].ValueType == typeof(string))
{ excel.Cells[i + 2, j + 1] = "'" + gridView[j, i].Value.ToString(); } else
{ excel.Cells[i + 2, j + 1] = gridView[j, i].Value.ToString(); } } } return true; }
this.openfiledialog.resourcedirectory=true;
....
Response.Write("<script language=javascript>this.parent.location.href='" + Path.Text.Trim() + "'</script>");方法,问题是解决了,但弹出的对话框中不仅有‘打开’还有‘保存’,我只想让它打开,不想让它保存下载,怎么解决呢?