Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
AnswerRe: WPF: use enum as index for Binding Pin
Eddy Vluggen20-Aug-12 0:48
professionalEddy Vluggen20-Aug-12 0:48 
GeneralRe: WPF: use enum as index for Binding Pin
LionAM20-Aug-12 1:41
LionAM20-Aug-12 1:41 
GeneralRe: WPF: use enum as index for Binding Pin
Eddy Vluggen20-Aug-12 1:47
professionalEddy Vluggen20-Aug-12 1:47 
QuestionTypedDataSet synchronisation using compact framework Pin
VenkataRamana.Gali19-Aug-12 23:11
VenkataRamana.Gali19-Aug-12 23:11 
AnswerRe: TypedDataSet synchronisation using compact framework Pin
Pete O'Hanlon20-Aug-12 0:17
mvePete O'Hanlon20-Aug-12 0:17 
GeneralRe: TypedDataSet synchronisation using compact framework Pin
VenkataRamana.Gali20-Aug-12 4:02
VenkataRamana.Gali20-Aug-12 4:02 
QuestionWCF SErvice Authentication Pin
pravin_mun19-Aug-12 20:21
pravin_mun19-Aug-12 20:21 
QuestionGetting File Path Pin
ASPnoob18-Aug-12 17:02
ASPnoob18-Aug-12 17:02 
Hi all,
I'm trying to create an app that lets people upload their resume to my database. I've seen tutorials for doing this and they all say the same thing. Number 1 save the original name and file type of the file to be uploaded and convert the file to byte array. Number 2 upload to database. However there is a problem, they all seem to assume one thing and that is, they assume the path of the file to be uploaded is known. Just to show you what I'm talking about below is one of the methods I've found that let you upload a file to the database.

C#
protected void InsertDoc_Click(object sender, EventArgs e)
    {
        // Read the file and convert it to Byte Array
        string filePath = Server.MapPath("APP_DATA/TestDoc.docx");
        string filename = Path.GetFileName(filePath);

        FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fs);
        Byte[] bytes = br.ReadBytes((Int32)fs.Length);
        br.Close();
        fs.Close();

        //insert the file into database
        string strQuery = "insert into tblFiles(Name, ContentType, Data) values (@Name, @ContentType, @Data)";
        SqlCommand cmd = new SqlCommand(strQuery);
        cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename;
        cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value = "application/vnd.ms-word";
        cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
        InsertUpdateData(cmd);
    }


The line
C#
string filePath = Server.MapPath("APP_DATA/TestDoc.docx");


is supposed to give you the file path but it assumes you already know what it is. I tried to get around this problem by using a FileUpload control and use fileupload1.PostedFile.FileName, but it only returns the file name and extension, not the full path. I have also tried Path.GetFileName( fileupload1.FileName) with no luck. How do I get around this problem? Thanks in advance for replying.

modified 18-Aug-12 23:30pm.

AnswerRe: etGetting File Path Pin
Richard Andrew x6418-Aug-12 17:17
professionalRichard Andrew x6418-Aug-12 17:17 
GeneralRe: etGetting File Path Pin
ASPnoob18-Aug-12 17:20
ASPnoob18-Aug-12 17:20 
GeneralRe: etGetting File Path Pin
Richard Andrew x6418-Aug-12 17:24
professionalRichard Andrew x6418-Aug-12 17:24 
AnswerRe: Getting File Path Pin
OriginalGriff18-Aug-12 19:42
mveOriginalGriff18-Aug-12 19:42 
GeneralRe: Getting File Path Pin
ASPnoob18-Aug-12 20:46
ASPnoob18-Aug-12 20:46 
GeneralRe: Getting File Path Pin
OriginalGriff18-Aug-12 21:29
mveOriginalGriff18-Aug-12 21:29 
AnswerRe: Getting File Path Pin
Ed Hill _5_18-Aug-12 23:58
Ed Hill _5_18-Aug-12 23:58 
GeneralRe: Getting File Path PinPopular
Pete O'Hanlon19-Aug-12 1:26
mvePete O'Hanlon19-Aug-12 1:26 
GeneralRe: Getting File Path Pin
OriginalGriff19-Aug-12 1:32
mveOriginalGriff19-Aug-12 1:32 
GeneralRe: Getting File Path Pin
Pete O'Hanlon19-Aug-12 1:52
mvePete O'Hanlon19-Aug-12 1:52 
AnswerRe: Getting File Path Pin
Pete O'Hanlon19-Aug-12 4:51
mvePete O'Hanlon19-Aug-12 4:51 
GeneralRe: Getting File Path ... foolishness Pin
Richard MacCutchan19-Aug-12 5:46
mveRichard MacCutchan19-Aug-12 5:46 
GeneralRe: Getting File Path ... foolishness Pin
Pete O'Hanlon19-Aug-12 5:53
mvePete O'Hanlon19-Aug-12 5:53 
GeneralRe: Getting File Path ... foolishness Pin
Richard MacCutchan19-Aug-12 6:01
mveRichard MacCutchan19-Aug-12 6:01 
GeneralRe: Getting File Path ... foolishness Pin
Pete O'Hanlon20-Aug-12 2:40
mvePete O'Hanlon20-Aug-12 2:40 
Questioncue banner not working Pin
Jassim Rahma17-Aug-12 4:22
Jassim Rahma17-Aug-12 4:22 
AnswerRe: cue banner not working Pin
Ravi Bhavnani17-Aug-12 4:41
professionalRavi Bhavnani17-Aug-12 4:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.