Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating XML records with File Info or PostedFile 1

Status
Not open for further replies.

ShonGill

Programmer
May 20, 2008
44
US
Hey Everbody,

I very new to ASP.NET and I'm still trying to get a grasp on all the .NET class stuff. I am building an image Upload/Resize/Crop/Delete interface. The image files will be saved on the files system and tracked with XML records.

As I said, I'm very new to ASP.NET and I've done alot of forum searching and what-not. this is my first Forum Post on the topic. I hope not to confuse, but I'm confused.

So far my page will upload the images to the file system directly, and seperately I can edit the images and post them into the XML file. I would like to be able to pass the File Name, File Path, Thumbnail Name & Thumbnail Path into a data column of each record in the XML file representing the file that was just uploaded.

BTW: I'm using a cool application called Radactive iLoad for the image editing. With a little tweeking, I can load the edited images into the XML file as it saves the file onto the File System. However I want to have a simpler method through the FileUpload control. How do I get the file attributes of the uploaded file to populate into the XML?

I noticed that that PostedFile.FileName will get the Fully Qualified Name and I can use the System.IO.Path.GetFileName to use only the name of the file and not the entire path. How do I then pass this info into a Data Column of the XML file?

I hope I have not confused, but like I said... I'm confused. I'm probably just mixing a few techniques together and it's not working out well. Anything you can tell me though would be helpful.

: )

this is all I have in my code behind, so far:

Code:
Partial Class PhotoMGR
    Inherits System.Web.UI.Page

    Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)

    	Dim MyPath, MyName As String

        MyPath = Server.MapPath("/PHOTOS/")
        MyName = Dir(MyPath, vbDirectory)

        If MyName = "" Then
        	MkDir("PHOTOS")
                Span2.InnerHtml = "A Folder (PHOTOS) was created at the opening of this page."
	End If

        Dim objdata as New DataSet

      		Try
        		objdata.ReadXML(Server.Mappath("/APP_DATA/PhotoStor.xml"))
        		datagrid1.Datasource = objdata
        		datagrid1.Databind()
  		Catch

			CreateXML

		End Try
    
    Sub Upload_Click(ByVal Sender As Object, ByVal e As EventArgs)

        FileName.InnerHtml = MyFile.PostedFile.FileName
        FileContent.InnerHtml = MyFile.PostedFile.ContentType
        UploadDetails.visible = True

        Dim strFileName As String
        strFileName = MyFile.PostedFile.FileName
        Dim c As String = System.IO.Path.GetFileName(strFileName)


    End Sub

    End Sub

      Sub CreateXML
      Dim objdata as New DataSet("root")
      Dim dt as New DataTable("record")
      Dim dr as DataRow

      dt.Columns.Add(New DataColumn("aid"))
      dt.Columns.Add(New DataColumn("filename"))
      dt.Columns.Add(New DataColumn("tagname"))
      dt.Columns.Add(New DataColumn("brand"))
      dt.Columns.Add(New DataColumn("desc"))
      dt.Columns.Add(New DataColumn("fileloc"))
      dt.Columns.Add(New DataColumn("brandimg"))

      dr=dt.NewRow()
      dr(0)="1"
      dr(1)="No Data"
      dr(2)="No Data"
      dr(3)="No Data"
      dr(4)="No Data"
      dr(5)="No Data"
      dr(6)="No Data"

      dt.Rows.Add(dr)

      objdata.Tables.Add(dt)

      datagrid1.datasource=objdata
      datagrid1.databind()

      objdata.WriteXML(Server.mappath("/APP_DATA/PhotoStor.xml"))

      LoadXML()
  End Sub
 
don't try/catch just to recreate the file. this will overwrite your data when an error is thrown. then you loose all your data. and you don't know what exception occurred

since your xml file is just a datatable the easiest solution is to keep with the datatable model. load the xml file into a data table. then add a row to the data. then write the datatable back to the file.

there are a lot of problems with this though.
1. multiple users writing to the same file.
2. file size.
3. extraneous read/writes
4. query inefficiency

to do anything with the xml will require you to load the entire file. there will be a performance penalty once the file gets too big.

for simplicity in reading the code you should break out responsibilities into members and objects with each having exactly 1 responsibility. this will be 1. much easier to read 2. much easier to maintain.

for example:
right now you are storing your data in xml. what if a few days/weeks/months/years from now you want to upgrade to a database.
right now you have to rewrite the whole page. if loading a datatable was done in it's own object you would only need to change the code in 1 place.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
the nature of the photo gallery requires the old images to beremoved to make way for the new images... hence the need for the interface. i'm trying to just parse the image location into the FLASH photo gallery with thumbnails.

my original plan was this:

1. iLoad to crop/resize images and it also makes thumbnails
2. iLoad to store the file names and locations into the XML
3. AS2 loads all the thumbs into emptyMovieClip on the preloader
4. AS2 parses in the images from XML only as they're selected

the problem is that iLoad has it's own class objects and has to be configured. I don't understand the standard well enough to know what to do yet... but iLoad is such a great looking application for editing images in ASP.NET

right now I'm working on a fileupload control as a backup. would I be able to just bing the control to the XML file? could it be that simple?

oh, thanks for the heads up on the Try... Catch... !

I didn't even recognize that could be a problem. anything else I'm not seeing???

: )

Dishon Gillis
Dominion Enterprises Company
 
the nature of the photo gallery requires the old images to beremoved to make way for the new images... hence the need for the interface.
this makes no sense in this context.
the problem is that iLoad has it's own class objects and has to be configured. I don't understand the standard well enough to know what to do yet...
if iLoad provides this functionality, then you need to study the api and use this to save the data. the api may also address the problems I posted about previously. don't waist time trying to hack the upload process if one already exists.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I was trying to tell you that everytime new photos are added to the XML (and FLASH photo gallery) all the existing photos will be removed... so there shouldn't be an issue with the XML file getting too large. also, there is only one person who would have access to changing the photos.


as far as the API goes... here's a link to what I'm talking about, maybe it will make more sense.


it's saying that it uses custom methods. what do they mean about refering to the CustomStorage in my web.config file?

Dishon Gillis
Dominion Enterprises Company
 
the link points to the summary page so I'm not sure exactly what your question about the web.config is.

if I had to guess.
customstorage is storage solution other than the default. when the application is first loaded information about where to store files is configured.
so if you wanted to store the files somewhere else you would create a configuration section in the web.config and set the new values there.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
yes, it's like a stated previously. the CustomStorage is just that. your storage solution (instead of the default). Your object must inherit the ICustomStorageManager. implement the members, update the config and your set to go.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
i haven't used the App_Code before. what should i be updating the config with?

Dishon Gillis
Dominion Enterprises Company
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top