[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2456
  • Last Modified:

asp.net c# image upload on server

Hello,I am uing ASp.net with C# ver 2 visual studio 2005 i have a project in which i have to uplaod Images and PDF files save them on SERVER and not dtabase in database only file name will be saved. saved files can be renamed. or resized. user later candelete thru web pages. please tell me which control to add on my aspx for  uploading images and pdf how 2 display them. thank you in advance I am in need for this any help is highly appreciated.

Thanks a ton Sanjay
0
dontnetsanjay
Asked:
dontnetsanjay
  • 4
  • 2
1 Solution
 
sabeeshCommented:
You can use FileUpload control for this

some sample code.

private bool Upload(FileUpload pFileUpload, int pRItemId)
    {
        bool result = false;

        //Grab the file name from its fully qualified path at client
        string strFileName = pFileUpload.PostedFile.FileName;

        // only the attched file name not its path
        string fileName = System.IO.Path.GetFileName(strFileName);
        fileName = pRItemId.ToString() + "_" + fileName;

        //Save uploaded file to server at C:\ServerFolder\
        try
        {
            //string filePath = ConfigurationManager.AppSettings["FilePath"]; //Server.MapPath(Request.Url.AbsoluteUri);
            string filePath = Server.MapPath("GenResources");
            pFileUpload.PostedFile.SaveAs(filePath + @"\" + fileName);
            //Response.Write(filePath + fileName);
            //Update ResourcePath
            //Set source file url in web.config.
            string hostFilePath = ConfigurationManager.AppSettings["FilePath"];
            string urlSourcePath = "http://" + Request.Url.Host + hostFilePath;
            //Response.Write(urlSourcePath);
            urlSourcePath = urlSourcePath + fileName;
            DataHelper oDataHelper = new DataHelper(Configuration.ConnectionString, "CA_Sp_UpdateResourcePath", CommandType.StoredProcedure);
            oDataHelper.moCommand.Parameters.AddWithValue("@RESOURCEPATH", urlSourcePath);
            oDataHelper.moCommand.Parameters.AddWithValue("@W_RESOURCEITEMSID", pRItemId);
            oDataHelper.moCommand.ExecuteNonQuery();
            oDataHelper.moCommand.Connection.Close();

        }
        catch (Exception ex)
        {
            //lblMessage.Visible = true;
            //lblMessage.Text = ex.Message;
        }
        return result;
    }
0
 
dontnetsanjayAuthor Commented:


hello again
thanks for sending complete code this is already a great help which cannot be ignored
but i am not able to get the thing clearly
my job is to develop a a module sothat client can enter his product info and upload image or pdf file as cataloge here in this quey i will remian with image upload and pdf i will start another question(chain)
==>
pRItemId is a variable to asign prefix to the filename?

dtahelper namespace could not be found??
in help search also i did not got any result?

and I am new to all this therefore its not easy for me

0
 
sabeeshCommented:
Sanjay,
           This is just a sample code only don't blindly copy this code, change as per your requirement. Here dtHelper is a custom class that you cannot find any where , that is used in our project. u can write your own code here.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dontnetsanjayAuthor Commented:

okay dthelper is basically our code for database connection string??
0
 
dontnetsanjayAuthor Commented:
okay now I am getting thiscode thanks anyway u helped me in this i am editing this code accordingly

 its 12.35 am working on this and post back in few min..
0
 
dontnetsanjayAuthor Commented:
thanks a lot my code is working

now
io had created a new subfolder in work folder there i have saved it
i guess i had to use '\' instead of this '/' which took little extra time

thanks once again
 
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now