Click here to Skip to main content
15,905,414 members
Home / Discussions / C#
   

C#

 
GeneralRe: Convert dateTime components to hex then byte[] Pin
MichCl20-Aug-12 7:37
MichCl20-Aug-12 7:37 
GeneralRe: Convert dateTime components to hex then byte[] Pin
DaveyM6920-Aug-12 11:12
professionalDaveyM6920-Aug-12 11:12 
GeneralRe: Convert dateTime components to hex then byte[] Pin
MichCl21-Aug-12 1:52
MichCl21-Aug-12 1:52 
GeneralRe: Convert dateTime components to hex then byte[] Pin
DaveyM6921-Aug-12 7:55
professionalDaveyM6921-Aug-12 7:55 
GeneralRe: Convert dateTime components to hex then byte[] Pin
MichCl21-Aug-12 8:47
MichCl21-Aug-12 8:47 
QuestionWPF: use enum as index for Binding Pin
LionAM19-Aug-12 23:38
LionAM19-Aug-12 23:38 
AnswerRe: WPF: use enum as index for Binding Pin
Pete O'Hanlon20-Aug-12 0:27
mvePete O'Hanlon20-Aug-12 0:27 
GeneralRe: WPF: use enum as index for Binding Pin
LionAM20-Aug-12 1:34
LionAM20-Aug-12 1:34 
GeneralRe: WPF: use enum as index for Binding Pin
Pete O'Hanlon20-Aug-12 1:37
mvePete O'Hanlon20-Aug-12 1:37 
GeneralRe: WPF: use enum as index for Binding Pin
LionAM20-Aug-12 1:47
LionAM20-Aug-12 1:47 
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 
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 
File upload controls don'#t give you any path information (because the device originating the file may not support paths, and the path to the original file would give you information about the client machine - which is not allowed for security reasons).

But that's ok, - you don't need it. You need the file name and extension - which all upload controls will give you - and you need the file content as a byte stream - which all upload controls will also give you. You don't need to read it any further to get the data you need, since you can't specific the destination location when any user uploads it anyway!

This is the method I use: it's probably a bit overkill for you since it handles versioning as well, but...

C#
/// <summary>
/// Save an upload into the database.
/// </summary>
/// <param name="fl">Control containing the download.</param>
/// <returns>Status as a string</returns>
private string SaveUpload(FileUpload fl)
    {
    if (fl.HasFile)
        {
        try
            {
            int version = 0;
            string filename = Path.GetFileName(fl.FileName);
            byte[] filedata = fl.FileBytes;
            string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DownloadDatabase"].ConnectionString;
            using (SqlConnection con = new SqlConnection(strCon))
                {
                con.Open();
                // Check version - if the file exists in the DB already, then increase version number.
                using (SqlCommand ver = new SqlCommand("SELECT MAX(version) FROM dlContent WHERE fileName=@FN", con))
                    {
                    ver.Parameters.AddWithValue("@FN", filename);
                    object o = ver.ExecuteScalar();
                    if (o != null && o != System.DBNull.Value)
                        {
                        // Exists already.
                        version = (int) o + 1;
                        }
                    }
                // Stick file into database.
                using (SqlCommand ins = new SqlCommand("INSERT INTO dlContent (iD, fileName, description, dataContent, version, uploadedOn) " +
                                                       "VALUES (@ID, @FN, @DS, @DT, @VS, @UD)", con))
                    {
                    ins.Parameters.AddWithValue("@ID", Guid.NewGuid());
                    ins.Parameters.AddWithValue("@FN", filename);
                    ins.Parameters.AddWithValue("@DS", "");
                    ins.Parameters.AddWithValue("@DT", filedata);
                    ins.Parameters.AddWithValue("@VS", version);
                    ins.Parameters.AddWithValue("@UD", DateTime.Now);
                    ins.ExecuteNonQuery();
                    }
                }
            return string.Format("{0} uploaded, version = {1}", filename, version);
            }
        catch (Exception ex)
            {
            return "The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    return "Please select a file.";
    }

Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

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 

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.