Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create image file from Text field
Message
From
10/09/2014 08:19:38
 
 
To
10/09/2014 07:58:07
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows Server 2008
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01607213
Message ID:
01607292
Views:
56
This message has been marked as the solution to the initial question of the thread.
>When running the query it says "Type blob is not a defined system type".
>When casting to VarBinary(max) it says "Explicit conversion from data type text to varbinary(max) is not allowed."


OK, I thought you were selecting from a vfp table

try
declare @test table

  ( field1 text );

insert into @test values('1234');

select cast(cast(field1 as varchar(max)) as varbinary(max))
 from @test;
>
>>I don't think you need any encoding at all.
>>
>>If it comes from a memo field
>>
>>string query = "SELECT cast(memofieldname as blob)as memofieldname  FROM ...";
>>
>>
>>The result should give the file contents as is
>>
>>>I have a Text field in the database (populated from VFP Memo field) that contains the file contents.
>>>In VFP they get created FILETOSTR() and retrieved STRTOFILE(), which works without problems.
>>>
>>>Now in a C# solution I need to pick up the file contents and copy them to a file, but the resulting file is not valid. I am not sure what is the missing piece in the code:
>>>
>>>String fileName;
>>>fileName = Path.Combine(System.IO.Path.GetTempPath(),
>>>              "Samplefile.jpg");
>>>
>>>if (System.IO.File.Exists(fileName) == true)
>>>  {
>>>     System.IO.File.Delete(fileName);
>>>  }
>>>
>>>FileStream oFs = new
>>>          FileStream(fileName, FileMode.CreateNew, FileAccess.ReadWrite);
>>>
>>>StreamWriter oWriter = new StreamWriter(oFs);
>>>
>>>ASCIIEncoding asciiEncoding = new ASCIIEncoding();
>>>oWriter.Write(asciiEncoding.GetBytes(reminderMainRow.reFile)); //That is the memo field.
>>>oWriter.Flush();
>>>oWriter.Close();
>>>oFs.Close();
>>>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform