hi
i'm writing a c# script to be used in ssis....
i'm trying to pull an image from a website...
i'm new to c# and i'm not sure whether the data types i'm using are right...
i'm posting my code here...
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace ST_09069b9ea31e4c45836292539999e637.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
string url = generateUrl();
getImage(url);
Dts.TaskResult = (int)ScriptResults.Success;
}
public string generateUrl()
{
WebRequest request = WebRequest.Create("http://www.movieposterdb.com/embed.inc.php?movie_id=0333766");
using (WebResponse response = request.GetResponse())
{
using (StreamReader responseReader =
new StreamReader(response.GetResponseStream()))
{
string responseData = responseReader.ReadToEnd();
int beg_pos = (responseData.IndexOf("src=")) + 6;
int end_pos = (responseData.Length) - 12;
string tempUrl = responseData.Substring(beg_pos, 76);
string imgUrl = tempUrl.Replace("t_", "l_");
return (imgUrl);
}
}
}
public void getImage(string url)
{
WebRequest request1 = WebRequest.Create(url);
using (WebResponse response1 = request1.GetResponse())
{
using (StreamReader responseReader =
new StreamReader(response1.GetResponseStream()))
{
object responseData1 = responseReader.ReadToEnd();
using (StreamWriter writer =
new StreamWriter(@"C:\SaveResponse\sample.jpg"))
{
writer.Write(responseData1);
}
}
}
}
}
}
when i open sample.jpg it says invalid image....
please help....