Wednesday 3 February 2010

iron speed: upload a file to file system and save the location in database...solved

This is the first time when a product documentation has come to my rescue. The iron speed code documentation has done the trick for me. I am trying to figure out a way to provide the code snippet a format other than image so that it can be in a ‘copy and paste’ format for later purposes. This is the image of the product documentation that had helped me for this particular problem. Okey first thing’s first. How I got around the problem? As I have discussed in phase one that I want upload a file into the filesystem using the fileInput control. At the same time I wanted to save that virtual address to the DB location. My approach was I will designate the savelocation value to the url Textbox and ask iron speed to take data from the url Textbox. Another approach may be to declare a hidden asp label. Then assign the savelocation value to the label. Iron speed will pull the data from the label. A normal procedure could have been taking the value from the input file directly. The reason I did not take the approach is because InputFile is an html control. I did not want to get in another hassle of converting html variable into aspx data. Rest is fairly easy.

public void try1_Click(object sender, EventArgs args)             {                 bool shouldRedirect = true;                 try1_Click_Base(sender, args);                                  //searching the html control called inputFile                 System.Web.UI.HtmlControls.HtmlInputFile inputFile;                 inputFile = ((System.Web.UI.HtmlControls.HtmlInputFile)(this.Page.FindControl("inputFile")));                  if ((!(inputFile.PostedFile == null) && (inputFile.PostedFile.ContentLength > 0)))                 {                     // getting the filename                     // getting the savelocation                      string fileName = System.IO.Path.GetFileName(inputFile.PostedFile.FileName);                     string saveLocation = (this.Page.Server.MapPath("..\\Data") + ("\\" + fileName));                       try                      {                         // start transaction to store the file location to DB                         DbUtils.StartTransaction();                              // saving file to file system                         inputFile.PostedFile.SaveAs(saveLocation);                          // setting the control value  = saveLocation                         this.ImageRecordControl.url.Text = saveLocation;                          // saving data to DB                         this.ImageRecordControl.SaveData();                         this.CommitTransaction(sender);                      }                                                               catch (Exception ex)                     {                         this.Page.Response.Write(("Error: " + ex.Message));                         shouldRedirect = false;                         BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);                         this.RollBackTransaction(sender);                     }                      finally                     {                         DbUtils.EndTransaction();                     }                      if (shouldRedirect)                     {                         this.ShouldSaveControlsToSession = true;                     }                  }                 else                  {                     this.Page.Response.Write("Please select a file to upload.");                 }         }








iron speed: upload a file to file system and save the location in database...[phase two] cont...

i'm having no luck with the problem. it should have been a piece of cake. it has turned up to be a very hard nut to crack. the only update of my situation here is, i just accidentally clicked on code documentation instead of code customization which was just next to it. I was just having a look then i came across to this image of the class hierarchy...may be it will help.....

Tuesday 2 February 2010

iron speed: upload a file to file system and save the location in database...[phase two]

Now let us talk a bit about save button. As I was checking the code behind I saw the onclick event handler for save is calling a method named SaveButton_Click_Base(). This is the method from where the data is posted into the DB. The first thing that I noticed is the method is in a section called Do not modify the Section. Here I go again, falling in place where I have to do a prohibited thing with small calibre of knowledge I got..... As you can see there are four string type variables. They are

  • TargetKey
  • DFKA
  • Id
  • value

A Response.Redirect command will unfold what values each of them hold.

iron speed: upload a file to file system and save the location in database...[phase one]

The image below show the page I am working in. When the save button is clicked the system stores what is in the url and id field. When the try1 button is clicked, the file in inputfile is stored in the DB. My approach as I have told you before is try to save the location in the db so that later on that location will be retrieved. As I ran through the codebehind class I saw that it creates customized function for onclick event for try1. The code snippet is given bellow, As you can see variable saveLocation stores the file in the virtual directory named ‘data’. So if I rephrase my problem statement then it would become like this, “I want the file to be stored in saveLocation and the value of id and savelocation should be stored in the database. so what i did is, i copied all the content of the codebehind separate file generate a new codebehind for the page.

iron speed: upload a file to file system and save the location in database...

I have come across to iron speed designer in my previous organization. I think it very handy when it comes to development content manager like website. It has support for AJAX and new .net framework 3.X. The choices of design options are limited when it comes develop a new kind of websites. I am building a website for a collage now. The site will hold almost all kind of student information, some staff information and some specific reports. In this website I intend to save images in the file system of the website and store the location of image to the database. Iron speed has a customization support for uploading a file in file system in this article but next phase of my problem has not yet been considered. Let us see if I can manage to solve the issue.

From a place miles away from my destination

This is year 2010....

The last time I have blogged is almost exactly three and half years ago. Although I have uploaded this blog with few of my researches every now and then, I haven’t been able to ‘blog’ in real sense if you know what I mean. If someone asks ‘What happened?’ I do not think that I have an appropriate answer for it. I have come across to many life changing events in these three years. Some have given me new prospective of life, and some were even worse than the horrific nightmares I see. Rest assured, I have left my dream of becoming youngest ever MSCRM and MSEPM professional miles away. I have started my life new as a rookie again. The blogs that I’ll post here after will be of the problems and issues that I come across to my day to day activities. It will not deal with EPM or CRM. Not anymore......