Sorry for simple question:
I want to load XML file by fileupload and save it in the field of Table with xml type. then restore it from sql and bind it to dropdown list with Handler?
One of the simplest ways is to use XmlDocument to load your file and process it
XmlDocument xmlDoc= new XmlDocument(); // Create an XML document object
xmlDoc.Load("yourXMLFile.xml"); // Load the XML document from the specified file
// Get elements
XmlNodeList foo = xmlDoc.GetElementsByTagName("foo");
XmlNodeList bar = xmlDoc.GetElementsByTagName("bar");
// Display the results
Console.WriteLine("foo: " + foo[0].InnerText);
Console.WriteLine("bar: " + bar[0].InnerText);
Because you're using it to return ALL elements based on their known name it will pop everything into an array. This makes it a lot easier to process multiple entries, for example:
<document>
<entry>
<foo>foo</foo>
<bar>bar</bar>
</entry>
<entry>
<foo>foo</foo>
<bar>bar</bar>
</entry>
</document>
Depending on the type of data I would recommend making your own class and storing the entries in an array or list of that class.
Once that's done you can easily reference them and use .net's SQL functions to insert the entries from the list into the database
You can find details of how to bind your dropdown list to the dataset here: Populating an ASP.Net Drop Down List with DataSet data from DataSet created with DataSet designer
Related
I am uploading some documents in Marklogic Server (doc, docx, pdf, txt etc). Now I am building an interface in HTML & XQuery that allows a user to enter a search term and if that matches the contents of any documents, then that document name is displayed in the grid. I am using search:search API for searching. Now I also want to show last modified date and author of the document in the grid. Every windows document have last modified date and author property. But how can I get this information from search:search API so that I can show these information in the grid ?
If you have enabled the settings "maintain last modified," Marklogic keeps the last modified information in document property fragments. However, this is unrelated to the properties information kept in Windows, which are lost by default when you load them in Marklogic.
If you want to retain the Windows properties data, set up a filter in Information Studio to populate the Marklogic property fragments with the data. Alternately, you could write your own XSLT and use xdmp:document-filter() to store the data directly in the document.
Once you have loaded your documents and populated them with the properties you need, you can access the data directly if stored in the document, or using xdmp:document-properties() if stored in document properties.
Can Richfaces (de)serialize objects? Say for instance, I have a row of data being displayed in a richfaces table. Can I serialize the row of data to a string and later deserialize it back into a row?
It is also possible to turn a JSON object into a string in javascript. The following link contains a good tutorial on JSON:
http://www.hunlock.com/blogs/Mastering_JSON_%28_JavaScript_Object_Notation_%29
You can serialize anything on the server-side - i.e. in a managed bean.
Then you can output it wherever you want with #{yourBean.yourSerializedJson} (or iterate over a collection of serialized data).
I am using GridView in asp .net and editing data with edit command field property (as we know after updating the edited row, we automatically update the database), and I want to use transactions (with begin to commit statement - including rollback) to commit this update query in database, after clicking in some button (after some events for example), not automatically to insert or update the edited data from grid directly to the DB...so I want to save them somewhere temporary (even many edited rows - not just one row) and then to confirm the transaction - to update the real tables in database...
Any suggestions are welcomed...
I've used some good links, but very helpful, like:
http://www.asp.net/learn/data-access/tutorial-63-cs.aspx
http://www.asp.net/learn/data-access/tutorial-66-cs.aspx
etc...
Well,
you can store your edited data in a DataTable in session. and then pass this data table as a bulk insert in to the database. 2 options are available for this
if you are using SQL Server 2005 you can use OpenXML to achieve this, as i have stated here
if you are using SQL Server 2008 youc an use Table Variables like i did here.
i hope it helps
First way:
Create session variable that will contain your DB object (DataTable or mapped objects).
The GridView should work with this instance instead of sending the data to the database.
Once editing is finished you may take the object from the session and save it in the way you normally do.
Second way:
I would use javascript to collect all changes on the client side while he is editing as a array of objects (each object is separate row).
Once the editing done, you can create json string from the collection and pass it to the server.
If your json object configuration is same as server class then you can use JavaScriptSerializer to deserialize your string into collection of object.
After that, you can save your objects in the way you normally do.
how to store files (pdf and word files) into sql database and how to display that files with an option of "save" , "open" from sql data base when user click. i am doing project using c# + asp.net web application
You need to do several things here:
1) Create UI page that allows users to upload files.
This page will have a FileUpload control to check for the desired extentions
2) Write code to save these files to a database
The files can be stored as binary blobs. It will be up to you and your application to decide the schema of your database. You may also choose one of many ORM tools to provide you access to the database from your code see
Linq2SQL
EntityFramework
ADO.net
Or see Creating A Data Access Layer
You have many choices, choose whatever seems most natural / easy for you.
3) Create a UI for the user to select existing files
This will use your ORM data layer to read back the lists of files and display some sort of buttons / links for the user to select and download
4) Retrieve the files from the database once the user selects one and return the file
Read this MSDN article about returning binary files
Furthermore, google around a bit, you'll probably find lots of existing solutions with frameworks like DNN etc.
To store files, you should check out Filestream from SQL Server 2008: http://msdn.microsoft.com/en-us/library/cc716724.aspx
Other traditional platforms have similar support (with binary or image data types).
An alternative is you can store the file in a shared filesystem, and only store the path to the file in the SQL table.
The most common way is to have two columns in the database for the file to be stored propley. 1 column holds the filename with its extensions(ex: file1.txt) and the 2nd column will be of datatype binary.
at the application level. a method gets the uploaded filename and converts it to an array of bytes. then this array is stored in sql in the binary field. the filename is stored in the 1st field.
to read the file back, another method will read the binary field from sql and convert it back to a FileStream then save it with the original filename(extension).
Use a fileUploaded to upload the file.
Read the file into a byte array:
byte[] data = System.File.ReadAllByte(File Path);
convert the byte[] to hex and store it in a nvarchhar data field in SQL
stringBuilder sb = new StringBuilder()
foreach(byte b in data)
{
sb.Append(b.ToString("X");
}
When you need to display it, convert it back to byte[] and create a file out of it, and let the user Open/Save it from there.
How to load, save and display data from GridView to XML? Not XML file on the hard disk, but a temporary XML variable to save it all in a single field of XML type in a database.
The gridview per se doesn't have any data - so you can't save any to disk.
Your gridview will be bound to a data source - a list of objects, a DataTable, anything - that's the data, and that can be saved to (and loaded from) disk.
Your easiest choice is to XML serialize the data to disk - or load it from there. You need to check into XML serialization.
Or check out the DataTable's ReadXml and WriteXml methods - they allow you to save a DataTable onto disk in XML format - or load it from a XML file on disk.
It can be as simple as this:
DataTable myData = new DataTable();
myData.ReadXml(#"C:\temp\mydatafile.xml");
// do some processing
myData.WriteXml(#"C:\temp\mydatafile.xml", XmlWriteMode.WriteSchema);
UPDATE:
if you want to store the XML into a string so you can dump it into a database, use this:
// write DataTable to memory stream as XML
MemoryStream memStm = new MemoryStream();
myData.WriteXml(memStm);
// read memory stream into a string variable
memStm.Position = 0;
string xmlContents = new StreamReader(memStm).ReadToEnd();
and then store your xmlContents to the database.
Marc
Why do you want to store the historical data in the database? Why not save the QueryString or whatever data was used to populate the gridview and rebind the data accordingly?
For instance if your user navigates to mypage.aspx?id=56&size=large&date=yesterday
you could load those options in a json object {"Id":"56","size":"large","date":"yesterday"} and store that in the database. Then, your data is up-to-date, and large datasets don't fill up your database table with redundant/outdated data.
Check out:
http://www.codeplex.com/Json
edit: and if you don't want to mess around with adding json, you can use anything as a delimiter, for example, have key/value pairs on separate lines and separate them with a pipe ('|')