Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a user profile page in my web site, and saved resume in SQL in Binary format.
Now i want to retrieve this resume from database and display the same in web site at specific location.

I am converting the binary file into string but it is giving incorrect output.

I have tried:-
C#
Convert.ToBase64String(bytes, 0, bytes.Length);
Encoding.ASCII.GetString(bytes);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();


Also when i use
C#
Context.Response.BinaryWrite(bytes);
the output is displayed on the top of the web page.

Please suggest how to show this in a Div or lable or Multi line text box.
Posted
Updated 15-Dec-14 2:55am
v2
Comments
Adam Zgagacz 15-Dec-14 9:16am    
You have to show us how do you convert resume to binary format before saving.
Yvan Rodrigues 15-Dec-14 9:42am    
What format is it in? Was it ASCII originally?
MAT1003 16-Dec-14 0:44am    
Adding Code

public void FileUpload(int? candidateID)
{
// Check to see if file was uploaded
if (FileUpload1.PostedFile != null)
{
// Get a reference to PostedFile object
HttpPostedFile myFile = FileUpload1.PostedFile;

// Get size of uploaded file
int nFileLen = myFile.ContentLength;

// make sure the size of the file is > 0
if (validatefile())
{
// Allocate a buffer for reading of the file
byte[] myData = new byte[nFileLen];

// Read uploaded file from the Stream
myFile.InputStream.Read(myData, 0, nFileLen);

// Create a name for the file to store
string strFilename = Path.GetFileName(myFile.FileName);

// Specify a "currently active folder"
string activeDir = Server.MapPath("~/UploadedFiles/CandidateDocuments/");

//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, "Candidate_" + candidateID + "/" + dlDocumentType.SelectedItem.Text);

// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);

// Combine the new file name with the path
newPath = System.IO.Path.Combine(newPath, strFilename);

// Write data into a file
WriteToFile(newPath, ref myData);

// Store it in database
WriteToDB(strFilename, myFile.ContentType, ref myData, candidateID, dlDocumentType.SelectedItem.Text);
}
}
}
------------------------------------
<pre lang="cs">private void WriteToFile(string strPath, ref byte[] Buffer)
{
// Create a file
FileStream newFile = new FileStream(strPath, FileMode.Create);

// Write data to the file
newFile.Write(Buffer, 0, Buffer.Length);

// Close file
newFile.Close();
}</pre>

----------------------------------------------------------
private void WriteToDB(string strName, string strType, ref byte[] Buffer, int? candidateID, string docType)
{
BusinessLogic.BusinessEntities.CandidateProfile obCandidate = new BusinessLogic.BusinessEntities.CandidateProfile();
obCandidate.Candidate_ID = candidateID;
obCandidate.FILE_NAME = strName;
obCandidate.FileSize = Buffer.Length.ToString();
obCandidate.ContentType = strType;
obCandidate.FileData = Buffer;
obCandidate.DocType = docType;
obCandidate.CREATED_BY = "Self";

obCandidate.hRMMethodName = "WriteToDB";
obCandidate.hRMPageName = "CandidateProfile";
obCandidate.hRMTabName = "Add Candidate";
obCandidate.hRMUserId = candidateID.ToString();

int? documentId = objCandidateDBA.add_candidateDocument(obCandidate);

BindCandidateDocuments(candidateID);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900