Answered by:
send xml file to database

Question
-
El salaam alekom
I have XML file, i want send it to database of my web site to use it again on site
How can i make application by C# to send xml file to my sql server of web site ?
Monday, February 23, 2009 8:22 PM
Answers
-
There are multiple ways of doing this. It depends on the SQL Server version you are using and if it supports the type.
example, if you are going to be storing just pure XML, just store it in the XML field, which is a datatype in SQL Server 2005 and higher.
otherwise, if you just want to store that but the datatype isnt supported, or you want to store any file, then create a Binary column, and then get the bytes[] of the assembly/file and then insert that into the database.
// example:
private byte[] GetFileBytes(string fileNameAndPath)
{
FileStream fs = System.IO.File.Open(fileNameAndPath, FileMode.Open);byte[] fileInfo = new byte[fs.Length];
int read = fs.Read(fileInfo, 0, (int)fs.Length);
fs.Close();
return fileInfo;
}
Then after that, simply call the method, get the bytes of the file, and insert into the database.
Does this help?
Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator- Proposed as answer by ahmedilyas Monday, March 2, 2009 7:00 PM
- Marked as answer by Michael Sun [MSFT]Microsoft employee, Moderator Tuesday, March 3, 2009 12:41 AM
Monday, March 2, 2009 6:54 PM
All replies
-
Use blob cloumn..
- Marked as answer by Michael Sun [MSFT]Microsoft employee, Moderator Thursday, February 26, 2009 3:33 AM
- Unmarked as answer by m_elzaiady Monday, March 2, 2009 11:26 AM
Tuesday, February 24, 2009 7:20 AM -
thank you,
but there are more details !Wednesday, February 25, 2009 10:55 PM -
What do you mean with "There are more details?"
Ewald - Please remember to mark the replies as answers if they help.Wednesday, February 25, 2009 11:24 PM -
Ewald Hofman said:
What do you mean with "There are more details?"
Ewald - Please remember to mark the replies as answers if they help.
i don't know how work withe blob column in my codeMonday, March 2, 2009 11:25 AM -
Just create a column in the database with the TEXT datatype.
Ewald - Please remember to mark the replies as answers if they help.Monday, March 2, 2009 11:49 AM -
There are multiple ways of doing this. It depends on the SQL Server version you are using and if it supports the type.
example, if you are going to be storing just pure XML, just store it in the XML field, which is a datatype in SQL Server 2005 and higher.
otherwise, if you just want to store that but the datatype isnt supported, or you want to store any file, then create a Binary column, and then get the bytes[] of the assembly/file and then insert that into the database.
// example:
private byte[] GetFileBytes(string fileNameAndPath)
{
FileStream fs = System.IO.File.Open(fileNameAndPath, FileMode.Open);byte[] fileInfo = new byte[fs.Length];
int read = fs.Read(fileInfo, 0, (int)fs.Length);
fs.Close();
return fileInfo;
}
Then after that, simply call the method, get the bytes of the file, and insert into the database.
Does this help?
Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator- Proposed as answer by ahmedilyas Monday, March 2, 2009 7:00 PM
- Marked as answer by Michael Sun [MSFT]Microsoft employee, Moderator Tuesday, March 3, 2009 12:41 AM
Monday, March 2, 2009 6:54 PM