i am quite new to c# and was wondering if i could get assistance on an issue im having with writing a binary file from the database to my local machine, this is the code i have:
Expand|Select|Wrap|Line Numbers
- string inputString = Convert.ToString(reader["Attachment"]);
- byte[] AttachmentByte;
- AttachmentByte = StringToByteArray(inputString);
- string dir = "";
- dir = reader["Attachment"].ToString();
- string FilePath = dir;
- // Specify a "currently active folder"
- string activeDir = @"C:\Documents and Settings";
- //Create a new subfolder under the current active folder
- string newPath = System.IO.Path.Combine(activeDir, "PDF Attachments");
- // Create a new file name.
- string newFileName = "Attachments.pdf";
- // Combine the new file name with the path
- newPath = System.IO.Path.Combine(activeDir, newFileName);
- // Create the file and write to it.
- // REMEMBER: System.IO.File.Create will overwrite the file if it already exists.
- //if (!System.IO.File.Exists(newPath))
- //{
- using (System.IO.FileStream fs = System.IO.File.Create(newPath))
- {
- for (byte i = 0; i < 100; i++)
- {
- fs.Write(AttachmentByte, 0, AttachmentByte.Length);
- }
- }
Expand|Select|Wrap|Line Numbers
- public static byte[] StringToByteArray(string inputString)
- {
- System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
- return encoding.GetBytes(inputString);
- }
is there something i am doing wrong?