C# SaveFileDialog未在生产环境中打开

C# SaveFileDialog未在生产环境中打开,c#,asp.net,C#,Asp.net,我有一个SaveFileDialog来保存数据库中的文件 在我将网站托管在IIS上之前,它工作正常。然后它开始打开调试器。 很明显,对话框被阻塞了,但我对我可以使用什么没有进一步的想法 我的密码是 SaveFileDialog save = new SaveFileDialog(); save.FileName = tbl.Rows[0][0].ToString(); if (save.ShowDialog() == DialogResult.OK && save.FileNa

我有一个SaveFileDialog来保存数据库中的文件

在我将网站托管在IIS上之前,它工作正常。然后它开始打开调试器。 很明显,对话框被阻塞了,但我对我可以使用什么没有进一步的想法

我的密码是

SaveFileDialog save = new SaveFileDialog();
save.FileName = tbl.Rows[0][0].ToString();

if (save.ShowDialog() == DialogResult.OK && save.FileName != "")
{
     FileStream FS1 = new FileStream(save.FileName, FileMode.Create);
     byte[] blob = (byte[])tbl.Rows[0][1];
     FS1.Write(blob, 0, blob.Length);
     FS1.Close();

     FS1 = null;
}

任何帮助都将不胜感激。

我猜您正在ASP.NET网站中使用Windows窗体SaveFileDialog。这是不可能的。也许它可以在您的开发机器上运行,因为Cassini服务是以当前用户的身份运行的

解决方案:


写一些适用于ASP.NET的东西

我想你是在ASP.NET网站上使用Windows窗体SaveFileDialog。这是不可能的。也许它可以在您的开发机器上运行,因为Cassini服务是以当前用户的身份运行的

String FileName = tbl.Rows[0][0].ToString();
String FilePath = "C:/...."; //Replace this

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
byte[] blob = File.ReadAllBytes(FilePath );
response.BinaryWrite(blob );
response.Flush();
response.End();
解决方案:


写一些适用于ASP.NET的东西

我想你是在ASP.NET网站上使用Windows窗体SaveFileDialog。这是不可能的。也许它可以在您的开发机器上运行,因为Cassini服务是以当前用户的身份运行的

String FileName = tbl.Rows[0][0].ToString();
String FilePath = "C:/...."; //Replace this

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
byte[] blob = File.ReadAllBytes(FilePath );
response.BinaryWrite(blob );
response.Flush();
response.End();
解决方案:


写一些适用于ASP.NET的东西

我想你是在ASP.NET网站上使用Windows窗体SaveFileDialog。这是不可能的。也许它可以在您的开发机器上运行,因为Cassini服务是以当前用户的身份运行的

String FileName = tbl.Rows[0][0].ToString();
String FilePath = "C:/...."; //Replace this

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
byte[] blob = File.ReadAllBytes(FilePath );
response.BinaryWrite(blob );
response.Flush();
response.End();
解决方案:


写一些适用于ASP.NET的东西

HttpContext.Current.Response.Write
HttpContext.Current.Response.BinaryWrite
,客户端浏览器应该处理如何保存它

String FileName = tbl.Rows[0][0].ToString();
String FilePath = "C:/...."; //Replace this

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
byte[] blob = File.ReadAllBytes(FilePath );
response.BinaryWrite(blob );
response.Flush();
response.End();
using System;
using System.IO;
using System.Web.UI;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    // 1.
    // Get path of byte file.
    string path = Server.MapPath("~/Adobe2.png");

    // 2.
    // Get byte array of file.
    byte[] byteArray = File.ReadAllBytes(path);

    // 3A.
    // Write byte array with BinaryWrite.
    Response.BinaryWrite(byteArray);

    // 3B.
    // Write with OutputStream.Write [commented out]
    // Response.OutputStream.Write(byteArray, 0, byteArray.Length);

    // 4.
    // Set content type.
    Response.ContentType = "image/png";
    }
}

中的示例有
HttpContext.Current.Response.Write
HttpContext.Current.Response.BinaryWrite
,客户端浏览器应该处理如何保存它

using System;
using System.IO;
using System.Web.UI;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    // 1.
    // Get path of byte file.
    string path = Server.MapPath("~/Adobe2.png");

    // 2.
    // Get byte array of file.
    byte[] byteArray = File.ReadAllBytes(path);

    // 3A.
    // Write byte array with BinaryWrite.
    Response.BinaryWrite(byteArray);

    // 3B.
    // Write with OutputStream.Write [commented out]
    // Response.OutputStream.Write(byteArray, 0, byteArray.Length);

    // 4.
    // Set content type.
    Response.ContentType = "image/png";
    }
}

中的示例有
HttpContext.Current.Response.Write
HttpContext.Current.Response.BinaryWrite
,客户端浏览器应该处理如何保存它

using System;
using System.IO;
using System.Web.UI;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    // 1.
    // Get path of byte file.
    string path = Server.MapPath("~/Adobe2.png");

    // 2.
    // Get byte array of file.
    byte[] byteArray = File.ReadAllBytes(path);

    // 3A.
    // Write byte array with BinaryWrite.
    Response.BinaryWrite(byteArray);

    // 3B.
    // Write with OutputStream.Write [commented out]
    // Response.OutputStream.Write(byteArray, 0, byteArray.Length);

    // 4.
    // Set content type.
    Response.ContentType = "image/png";
    }
}

中的示例有
HttpContext.Current.Response.Write
HttpContext.Current.Response.BinaryWrite
,客户端浏览器应该处理如何保存它

using System;
using System.IO;
using System.Web.UI;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    // 1.
    // Get path of byte file.
    string path = Server.MapPath("~/Adobe2.png");

    // 2.
    // Get byte array of file.
    byte[] byteArray = File.ReadAllBytes(path);

    // 3A.
    // Write byte array with BinaryWrite.
    Response.BinaryWrite(byteArray);

    // 3B.
    // Write with OutputStream.Write [commented out]
    // Response.OutputStream.Write(byteArray, 0, byteArray.Length);

    // 4.
    // Set content type.
    Response.ContentType = "image/png";
    }
}

作为您的
FileStream
s的
Dispose()
的一个附带示例。将其设置为null不会给您带来任何好处。若要在Ed上扩展,请使用
using
语句清理您的文件流。作为备用,
FileStream的
Dispose()
。将其设置为null不会给您带来任何好处。若要在Ed上扩展,请使用
using
语句清理您的文件流。作为备用,
FileStream的
Dispose()
。将其设置为null不会给您带来任何好处。若要在Ed上扩展,请使用
using
语句清理您的文件流。作为备用,
FileStream的
Dispose()
。将其设置为null不会给您带来任何好处。要在Ed上扩展,请使用
using
语句来清理文件流。那么问题是什么?你有错误吗?这对我来说似乎是一个不错的解决方案。那么问题是什么呢?你有错误吗?这对我来说似乎是一个不错的解决方案。那么问题是什么呢?你有错误吗?这对我来说似乎是一个不错的解决方案。那么问题是什么呢?你有错误吗?对我来说,这似乎是一个不错的解决办法。