Hi,
Thanks for the great response. I have created a hack for the time being, until I can get the HTTP right. My temporary solution is creating a stored proc that reads a file from the intranet and sends it to the calling code, so for now no need for HTTP access, it uses the SQL port. Let me know what you guys think, like performance and other related issues I may face with this. Thanks again!
PROC:
ALTER
PROCEDURE [dbo].[pr_COMMON_ImportTempFile]
@Filename NVARCHAR(512)
AS
BEGIN
DECLARE @Sql NVARCHAR(512)
DECLARE @ID INT
SET @Sql = 'INSERT INTO tb_COMMON_TempFiles (FileData, FileName) SELECT *, ''' + @Filename + ''' FROM OPENROWSET(BULK N''' + @Filename + ''', SINGLE_BLOB) AS Document'
EXEC (@sql)
SELECT FileData FROM tb_COMMON_TempFiles WHERE FileName = @Filename
DELETE tb_COMMON_TempFiles WHERE FileName = @Filename
END
CODE:
public static Stream GetImage(string filename)
{
using (SqlConnection connection = new SqlConnection("Data Source=server18;Initial Catalog=Test;User ID=test;Password = test;"))
{
using (SqlCommand command = new SqlCommand("pr_COMMON_ImportTempFile", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@filename", filename));
connection.Open();
object result = command.ExecuteScalar();
try
{
return new MemoryStream((byte[])result);
}
catch
{
return null;
}
}
}
}
public void ProcessRequest()
{
//Set up the response settings
Response.ContentType = "image/jpeg";
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.BufferOutput = false;
// Setup the PhotoID Parameter
Int32 id = -1;
Stream stream = null;
//id = Convert.ToInt32(Request.QueryString["PhotoID"]);
stream = GetImage(@"\\server18\Attachments\11345image.jpg");
const int buffersize = 1024 * 16;
byte[] buffer2 = new byte[buffersize];
int count = stream.Read(buffer2, 0, buffersize);
while (count > 0)
{
Response.OutputStream.Write(buffer2, 0, count);
count = stream.Read(buffer2, 0, buffersize);
}
}