|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SQL BLOB data back into a stringNot sure if this is the right place, sorry if it isn't, but just point me to the right spot if not. My problem, another developer has stored some text, html, images, etc into a table field that is a blob. The problem is, in an asp.net page, I need to get the HTMl back out of the blob and into a string to manipulate the src & href attributes in some of the HTML tags. I can used the system.convert methods to decode the base64 string that comes back, but stumped how to convert the content back into it's original string data form. I have tried search every where for hints on how to do this, with no luck. Can anyone point me to or have a code snippit in eithe rvb.net or C# how this is done? -- Cheers, Jake This particular code snippet example is getting an image blob and saving it to a file. Use the same code but access the table column in your server's database.
SqlConnection con = new SqlConnection("Server=Darkover;uid=<username>;pwd=<strong password>;database=northwind"); SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con); SqlCommandBuilder MyCB = new SqlCommandBuilder(da); DataSet ds = new DataSet("MyImages"); byte[] MyData= new byte[0]; da.Fill(ds, "MyImages"); DataRow myRow; myRow=ds.Tables["MyImages"].Rows[0]; MyData = (byte[])myRow["imgField"]; int ArraySize = new int(); ArraySize = MyData.GetUpperBound(0); FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", FileMode.OpenOrCreate, FileAccess.Write); fs.Write(MyData, 0,ArraySize); fs.Close(); Show quote "Jake" <J***@discussions.microsoft.com> wrote in message news:9CB3CE08-3A2D-46E4-9A90-B05609560D56@microsoft.com... > I'm stumped, > > Not sure if this is the right place, sorry if it isn't, but just point me to > the right spot if not. > > My problem, another developer has stored some text, html, images, etc into a > table field that is a blob. > > The problem is, in an asp.net page, I need to get the HTMl back out of the > blob and into a string to manipulate the src & href attributes in some of the > HTML tags. > > I can used the system.convert methods to decode the base64 string that comes > back, but stumped how to convert the content back into it's original string > data form. > > I have tried search every where for hints on how to do this, with no luck. > Can anyone point me to or have a code snippit in eithe rvb.net or C# how this > is done? > > -- > Cheers, > > Jake Yosh,
Thanks for your response ... I'm OK at getting it out and if required sending it to the browser or the file system.... no problem here. The problem is if I want to manipulate the HTML that the blob contains, so the problem is, once I get the blob from SQL Svr, how to convert the data back into it's original text form (i.e. HTML). That's my stumbling block ... -- Show quoteCheers, Jake "Yosh" wrote: > This particular code snippet example is getting an image blob and saving it to a file. Use the same code but access the table column in your server's database. > > SqlConnection con = new SqlConnection("Server=Darkover;uid=<username>;pwd=<strong password>;database=northwind"); > SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con); > SqlCommandBuilder MyCB = new SqlCommandBuilder(da); > DataSet ds = new DataSet("MyImages"); > > byte[] MyData= new byte[0]; > > da.Fill(ds, "MyImages"); > DataRow myRow; > myRow=ds.Tables["MyImages"].Rows[0]; > > MyData = (byte[])myRow["imgField"]; > int ArraySize = new int(); > ArraySize = MyData.GetUpperBound(0); > > FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", FileMode.OpenOrCreate, FileAccess.Write); > fs.Write(MyData, 0,ArraySize); > fs.Close(); > > > > "Jake" <J***@discussions.microsoft.com> wrote in message news:9CB3CE08-3A2D-46E4-9A90-B05609560D56@microsoft.com... > > I'm stumped, > > > > Not sure if this is the right place, sorry if it isn't, but just point me to > > the right spot if not. > > > > My problem, another developer has stored some text, html, images, etc into a > > table field that is a blob. > > > > The problem is, in an asp.net page, I need to get the HTMl back out of the > > blob and into a string to manipulate the src & href attributes in some of the > > HTML tags. > > > > I can used the system.convert methods to decode the base64 string that comes > > back, but stumped how to convert the content back into it's original string > > data form. > > > > I have tried search every where for hints on how to do this, with no luck. > > Can anyone point me to or have a code snippit in eithe rvb.net or C# how this > > is done? > > > > -- > > Cheers, > > > > Jake Jake,
Perhaps, one or more of the following KB articles might fit your needs... 258038 HOWTO: Access and Modify SQL Server BLOB Data by Using the ADO Stream Object http://support.microsoft.com/?kbid=258038 309158 HOW TO: Read and Write BLOB Data by Using ADO.NET with C# http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158 308042 HOW TO: Read and Write BLOB Data by Using ADO.NET with VB.NET http://support.microsoft.com/default.aspx?scid=kb;EN-US;308042 326502 HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET http://support.microsoft.com/?id=326502 Regards, John --- SQL Full Text Search Blog http://spaces.msn.com/members/jtkane/ Show quote "Jake" <J***@discussions.microsoft.com> wrote in message news:6D8A094B-EC05-4937-93D2-51502FC2DB97@microsoft.com... > Yosh, > Thanks for your response ... I'm OK at getting it out and if required > sending it to the browser or the file system.... no problem here. > > The problem is if I want to manipulate the HTML that the blob contains, so > the problem is, once I get the blob from SQL Svr, how to convert the data > back into it's original text form (i.e. HTML). That's my stumbling block > ... > > -- > Cheers, > > Jake > > > "Yosh" wrote: > >> This particular code snippet example is getting an image blob and saving >> it to a file. Use the same code but access the table column in your >> server's database. >> >> SqlConnection con = new >> SqlConnection("Server=Darkover;uid=<username>;pwd=<strong >> password>;database=northwind"); >> SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con); >> SqlCommandBuilder MyCB = new SqlCommandBuilder(da); >> DataSet ds = new DataSet("MyImages"); >> >> byte[] MyData= new byte[0]; >> >> da.Fill(ds, "MyImages"); >> DataRow myRow; >> myRow=ds.Tables["MyImages"].Rows[0]; >> >> MyData = (byte[])myRow["imgField"]; >> int ArraySize = new int(); >> ArraySize = MyData.GetUpperBound(0); >> >> FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", >> FileMode.OpenOrCreate, FileAccess.Write); >> fs.Write(MyData, 0,ArraySize); >> fs.Close(); >> >> >> >> "Jake" <J***@discussions.microsoft.com> wrote in message >> news:9CB3CE08-3A2D-46E4-9A90-B05609560D56@microsoft.com... >> > I'm stumped, >> > >> > Not sure if this is the right place, sorry if it isn't, but just point >> > me to >> > the right spot if not. >> > >> > My problem, another developer has stored some text, html, images, etc >> > into a >> > table field that is a blob. >> > >> > The problem is, in an asp.net page, I need to get the HTMl back out of >> > the >> > blob and into a string to manipulate the src & href attributes in some >> > of the >> > HTML tags. >> > >> > I can used the system.convert methods to decode the base64 string that >> > comes >> > back, but stumped how to convert the content back into it's original >> > string >> > data form. >> > >> > I have tried search every where for hints on how to do this, with no >> > luck. >> > Can anyone point me to or have a code snippit in eithe rvb.net or C# >> > how this >> > is done? >> > >> > -- >> > Cheers, >> > >> > Jake Thanks John,
I came across these KB's previously, all showing how to take a blob that contains an image of some sort (.jpg/.gif) and feed it the file system or browser. What I need is how to take the SQL BLOB content that has an HTML/text as content and decode this from the BLOB back into text form for additional manipulation before it is sent to the browser. I need to parse out the tag src and href attributes to point to the location where the other resources are located. -- Show quoteCheers, Jake "John Kane" wrote: > Jake, > Perhaps, one or more of the following KB articles might fit your needs... > 258038 HOWTO: Access and Modify SQL Server BLOB Data by Using the ADO Stream > Object > http://support.microsoft.com/?kbid=258038 > > 309158 HOW TO: Read and Write BLOB Data by Using ADO.NET with C# > http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158 > > 308042 HOW TO: Read and Write BLOB Data by Using ADO.NET with VB.NET > http://support.microsoft.com/default.aspx?scid=kb;EN-US;308042 > > 326502 HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET > http://support.microsoft.com/?id=326502 > > Regards, > John > --- > SQL Full Text Search Blog > http://spaces.msn.com/members/jtkane/ > > > > > "Jake" <J***@discussions.microsoft.com> wrote in message > news:6D8A094B-EC05-4937-93D2-51502FC2DB97@microsoft.com... > > Yosh, > > Thanks for your response ... I'm OK at getting it out and if required > > sending it to the browser or the file system.... no problem here. > > > > The problem is if I want to manipulate the HTML that the blob contains, so > > the problem is, once I get the blob from SQL Svr, how to convert the data > > back into it's original text form (i.e. HTML). That's my stumbling block > > ... > > > > -- > > Cheers, > > > > Jake > > > > > > "Yosh" wrote: > > > >> This particular code snippet example is getting an image blob and saving > >> it to a file. Use the same code but access the table column in your > >> server's database. > >> > >> SqlConnection con = new > >> SqlConnection("Server=Darkover;uid=<username>;pwd=<strong > >> password>;database=northwind"); > >> SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con); > >> SqlCommandBuilder MyCB = new SqlCommandBuilder(da); > >> DataSet ds = new DataSet("MyImages"); > >> > >> byte[] MyData= new byte[0]; > >> > >> da.Fill(ds, "MyImages"); > >> DataRow myRow; > >> myRow=ds.Tables["MyImages"].Rows[0]; > >> > >> MyData = (byte[])myRow["imgField"]; > >> int ArraySize = new int(); > >> ArraySize = MyData.GetUpperBound(0); > >> > >> FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", > >> FileMode.OpenOrCreate, FileAccess.Write); > >> fs.Write(MyData, 0,ArraySize); > >> fs.Close(); > >> > >> > >> > >> "Jake" <J***@discussions.microsoft.com> wrote in message > >> news:9CB3CE08-3A2D-46E4-9A90-B05609560D56@microsoft.com... > >> > I'm stumped, > >> > > >> > Not sure if this is the right place, sorry if it isn't, but just point > >> > me to > >> > the right spot if not. > >> > > >> > My problem, another developer has stored some text, html, images, etc > >> > into a > >> > table field that is a blob. > >> > > >> > The problem is, in an asp.net page, I need to get the HTMl back out of > >> > the > >> > blob and into a string to manipulate the src & href attributes in some > >> > of the > >> > HTML tags. > >> > > >> > I can used the system.convert methods to decode the base64 string that > >> > comes > >> > back, but stumped how to convert the content back into it's original > >> > string > >> > data form. > >> > > >> > I have tried search every where for hints on how to do this, with no > >> > luck. > >> > Can anyone point me to or have a code snippit in eithe rvb.net or C# > >> > how this > >> > is done? > >> > > >> > -- > >> > Cheers, > >> > > >> > Jake > > > Jake,
Let's just say for grins, you take the code provided in these posts and you read the blob field and write to a file. What does the contents of the file look like? Yosh Show quote "Jake" <J***@discussions.microsoft.com> wrote in message news:B473001D-E3FB-43FF-AEBC-A8C3BB3764A0@microsoft.com... > Thanks John, > > I came across these KB's previously, all showing how to take a blob that > contains an image of some sort (.jpg/.gif) and feed it the file system or > browser. > > What I need is how to take the SQL BLOB content that has an HTML/text as > content and decode this from the BLOB back into text form for additional > manipulation before it is sent to the browser. > > I need to parse out the tag src and href attributes to point to the > location > where the other resources are located. > -- > Cheers, > > Jake > > > "John Kane" wrote: > >> Jake, >> Perhaps, one or more of the following KB articles might fit your needs... >> 258038 HOWTO: Access and Modify SQL Server BLOB Data by Using the ADO >> Stream >> Object >> http://support.microsoft.com/?kbid=258038 >> >> 309158 HOW TO: Read and Write BLOB Data by Using ADO.NET with C# >> http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158 >> >> 308042 HOW TO: Read and Write BLOB Data by Using ADO.NET with VB.NET >> http://support.microsoft.com/default.aspx?scid=kb;EN-US;308042 >> >> 326502 HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET >> http://support.microsoft.com/?id=326502 >> >> Regards, >> John >> --- >> SQL Full Text Search Blog >> http://spaces.msn.com/members/jtkane/ >> >> >> >> >> "Jake" <J***@discussions.microsoft.com> wrote in message >> news:6D8A094B-EC05-4937-93D2-51502FC2DB97@microsoft.com... >> > Yosh, >> > Thanks for your response ... I'm OK at getting it out and if required >> > sending it to the browser or the file system.... no problem here. >> > >> > The problem is if I want to manipulate the HTML that the blob contains, >> > so >> > the problem is, once I get the blob from SQL Svr, how to convert the >> > data >> > back into it's original text form (i.e. HTML). That's my stumbling >> > block >> > ... >> > >> > -- >> > Cheers, >> > >> > Jake >> > >> > >> > "Yosh" wrote: >> > >> >> This particular code snippet example is getting an image blob and >> >> saving >> >> it to a file. Use the same code but access the table column in your >> >> server's database. >> >> >> >> SqlConnection con = new >> >> SqlConnection("Server=Darkover;uid=<username>;pwd=<strong >> >> password>;database=northwind"); >> >> SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con); >> >> SqlCommandBuilder MyCB = new SqlCommandBuilder(da); >> >> DataSet ds = new DataSet("MyImages"); >> >> >> >> byte[] MyData= new byte[0]; >> >> >> >> da.Fill(ds, "MyImages"); >> >> DataRow myRow; >> >> myRow=ds.Tables["MyImages"].Rows[0]; >> >> >> >> MyData = (byte[])myRow["imgField"]; >> >> int ArraySize = new int(); >> >> ArraySize = MyData.GetUpperBound(0); >> >> >> >> FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", >> >> FileMode.OpenOrCreate, FileAccess.Write); >> >> fs.Write(MyData, 0,ArraySize); >> >> fs.Close(); >> >> >> >> >> >> >> >> "Jake" <J***@discussions.microsoft.com> wrote in message >> >> news:9CB3CE08-3A2D-46E4-9A90-B05609560D56@microsoft.com... >> >> > I'm stumped, >> >> > >> >> > Not sure if this is the right place, sorry if it isn't, but just >> >> > point >> >> > me to >> >> > the right spot if not. >> >> > >> >> > My problem, another developer has stored some text, html, images, >> >> > etc >> >> > into a >> >> > table field that is a blob. >> >> > >> >> > The problem is, in an asp.net page, I need to get the HTMl back out >> >> > of >> >> > the >> >> > blob and into a string to manipulate the src & href attributes in >> >> > some >> >> > of the >> >> > HTML tags. >> >> > >> >> > I can used the system.convert methods to decode the base64 string >> >> > that >> >> > comes >> >> > back, but stumped how to convert the content back into it's original >> >> > string >> >> > data form. >> >> > >> >> > I have tried search every where for hints on how to do this, with no >> >> > luck. >> >> > Can anyone point me to or have a code snippit in eithe rvb.net or C# >> >> > how this >> >> > is done? >> >> > >> >> > -- >> >> > Cheers, >> >> > >> >> > Jake >> >> >> Yosh
OK, so I now feel stupid ... using your first code snippit with some changes to work in my setup, the file produced actually contained HTML that I desired. My code sample ... Dim sbHTMLdata As New stringbuilder Dim con As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("dsn")) Dim da As SqlDataAdapter = New SqlDataAdapter("Select * From Files where fileid=9", con) Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As DataSet = New DataSet("myBlob") Dim MyData() As Byte = New Byte(0) {} da.Fill(ds, "myBlob") Dim myRow As DataRow myRow = ds.Tables("myBlob").Rows(0) MyData = CType(myRow("blob"), Byte()) Dim ArraySize As Integer = New Integer ArraySize = MyData.GetUpperBound(0) Dim x As Integer For x = 0 To ArraySize sbHTMLdata.Append(Chr(MyData(x))) Next 'I know have my string of HTML - Cool Dim strHTML = sbHTMLdata.ToString So what did I miss here? How does it do the conversion from the binary blob to text? BTW, thanks, at least I see what is required to get at the text/html. -- Show quoteCheers, Jake "Yosh" wrote: > Jake, > > Let's just say for grins, you take the code provided in these posts and you > read the blob field and write to a file. What does the contents of the file > look like? > > Yosh > > "Jake" <J***@discussions.microsoft.com> wrote in message > news:B473001D-E3FB-43FF-AEBC-A8C3BB3764A0@microsoft.com... > > Thanks John, > > > > I came across these KB's previously, all showing how to take a blob that > > contains an image of some sort (.jpg/.gif) and feed it the file system or > > browser. > > > > What I need is how to take the SQL BLOB content that has an HTML/text as > > content and decode this from the BLOB back into text form for additional > > manipulation before it is sent to the browser. > > > > I need to parse out the tag src and href attributes to point to the > > location > > where the other resources are located. > > -- > > Cheers, > > > > Jake > > > > > > "John Kane" wrote: > > > >> Jake, > >> Perhaps, one or more of the following KB articles might fit your needs... > >> 258038 HOWTO: Access and Modify SQL Server BLOB Data by Using the ADO > >> Stream > >> Object > >> http://support.microsoft.com/?kbid=258038 > >> > >> 309158 HOW TO: Read and Write BLOB Data by Using ADO.NET with C# > >> http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158 > >> > >> 308042 HOW TO: Read and Write BLOB Data by Using ADO.NET with VB.NET > >> http://support.microsoft.com/default.aspx?scid=kb;EN-US;308042 > >> > >> 326502 HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET > >> http://support.microsoft.com/?id=326502 > >> > >> Regards, > >> John > >> --- > >> SQL Full Text Search Blog > >> http://spaces.msn.com/members/jtkane/ > >> > >> > >> > >> > >> "Jake" <J***@discussions.microsoft.com> wrote in message > >> news:6D8A094B-EC05-4937-93D2-51502FC2DB97@microsoft.com... > >> > Yosh, > >> > Thanks for your response ... I'm OK at getting it out and if required > >> > sending it to the browser or the file system.... no problem here. > >> > > >> > The problem is if I want to manipulate the HTML that the blob contains, > >> > so > >> > the problem is, once I get the blob from SQL Svr, how to convert the > >> > data > >> > back into it's original text form (i.e. HTML). That's my stumbling > >> > block > >> > ... > >> > > >> > -- > >> > Cheers, > >> > > >> > Jake > >> > > >> > > >> > "Yosh" wrote: > >> > > >> >> This particular code snippet example is getting an image blob and > >> >> saving > >> >> it to a file. Use the same code but access the table column in your > >> >> server's database. > >> >> > >> >> SqlConnection con = new > >> >> SqlConnection("Server=Darkover;uid=<username>;pwd=<strong > >> >> password>;database=northwind"); > >> >> SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con); > >> >> SqlCommandBuilder MyCB = new SqlCommandBuilder(da); > >> >> DataSet ds = new DataSet("MyImages"); > >> >> > >> >> byte[] MyData= new byte[0]; > >> >> > >> >> da.Fill(ds, "MyImages"); > >> >> DataRow myRow; > >> >> myRow=ds.Tables["MyImages"].Rows[0]; > >> >> > >> >> MyData = (byte[])myRow["imgField"]; > >> >> int ArraySize = new int(); > >> >> ArraySize = MyData.GetUpperBound(0); > >> >> > >> >> FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", > >> >> FileMode.OpenOrCreate, FileAccess.Write); > >> >> fs.Write(MyData, 0,ArraySize); > >> >> fs.Close(); > >> >> > >> >> > >> >> > >> >> "Jake" <J***@discussions.microsoft.com> wrote in message > >> >> news:9CB3CE08-3A2D-46E4-9A90-B05609560D56@microsoft.com... > >> >> > I'm stumped, > >> >> > > >> >> > Not sure if this is the right place, sorry if it isn't, but just > >> >> > point > >> >> > me to > >> >> > the right spot if not. > >> >> > > >> >> > My problem, another developer has stored some text, html, images, > >> >> > etc > >> >> > into a > >> >> > table field that is a blob. > >> >> > > >> >> > The problem is, in an asp.net page, I need to get the HTMl back out > >> >> > of > >> >> > the > >> >> > blob and into a string to manipulate the src & href attributes in > >> >> > some > >> >> > of the > >> >> > HTML tags. > >> >> > > >> >> > I can used the system.convert methods to decode the base64 string > >> >> > that > >> >> > comes > >> >> > back, but stumped how to convert the content back into it's original > >> >> > string > >> >> > data form. > >> >> > > >> >> > I have tried search every where for hints on how to do this, with no > >> >> > luck. > >> >> > Can anyone point me to or have a code snippit in eithe rvb.net or C# > >> >> > how this > >> >> > is done? > >> >> > > >> >> > -- > >> >> > Cheers, > >> >> > > >> >> > Jake > >> > >> > >> > > >
Other interesting topics
|
|||||||||||||||||||||||