16,008,075 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by MAT1003 (Top 1 by date)
MAT1003
16-Dec-14 0:44am
View
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);
}