.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

FileUpload.SaveAs Problem

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net

I'm uploading multiple PDF files from a CD to a folder on a server locally on the server itself. My problem is that the filenames and the PDF files is being uploaded, but the content of those PDF files themselves are missing. Their size is 0KB. 

FileUpload1.SaveAs(("C:\Documents and Settings\ABC\ABCD\ABCDE\PDF\" & Path.GetFileName((files(intCount1).ToString))
Not sure what i'm doing wrong here. I've tried a lot of other ways and I either get the path isn't found or or access is denied.
Thanks in advance for any help you guys can provide.




View Complete Post

More Related Resource Links

FileUpload Class SaveAs, how can you overwrite?

Hello all,

I'm trying to use 2.0 class, FileUpload. 
Namespace: System.Web.UI.WebControls
Class FileUpload

Anyway, in my code can save the file to the server

FileUpload1.SaveAs(SavePath + FileName)

Problem is I can't find a way to overwrite the file.  When I try and run the program again is says the file is already in use that a process has access to it.

Is thre a proper way to release control of whatever it grabbing hold of it?  In .Net I don't have to destroy my objects right?
Or is there a way to specificly overwrite the file? It seems that SaveAs does that.  Just trying to figure out why I can upload this text file, but sometimes only once and then I have to code in to check to see if it exists then rename it.

FileUpload.SaveAs is configured to require a rooted path. but "http:// --- is not a rooted path


Hi Friends

when i am uploading image to http://filepath i got the 

The FileUpload.SaveAs Method is configured to require a rooted path but http:// filepath is not a rooted path

my code is as follows

If (Fileupload.HasFile)


Dim filepath As String = http://filepath/

FileUpload.SaveAs(filepath & String.Format("datafield_{0}_b.jpg", textbox.Text))

End If

Please help me




Problem in "Upload a picture into data base" because is in

Hi guys. I can upload a picture into database by this code correctly in a web page without "UpdatePanel": ******************************** SqlConnection connection = null; try { Byte[] imgByte = null; if (FileUpload.HasFile && FileUpload.PostedFile != null) { HttpPostedFile File = FileUpload.PostedFile; imgByte = new Byte[File.ContentLength]; File.InputStream.Read(imgByte, 0, File.ContentLength); } // Insert the employee name and image into db string conn = "Data Source=PC5;Initial Catalog=LaptopStore;Integrated Security=True"; connection = new SqlConnection(conn); connection.Open(); string sql = "INSERT INTO test(image) VALUES(@image) SELECT @@IDENTITY"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@image", imgByte); int id = Convert.ToInt32(cmd.ExecuteScalar()); lblResult.Text = String.Format("Employee ID is {0}", id); } catch { lblResult.Text = "There was an error"; } finally { connection.Close(); } ******************************************** But when I want to use this code in a

FileUpload path problem


I have not been able to uplaod a file to my web page although the code I am using works if I copy it locally. Perhaps I am missing something in the path or I need to change some security setting on the web page?

   protected void btnUpload_Click(object sender, EventArgs e)
        SelectedFileName.InnerHtml = txtFileField.PostedFile.FileName;
        FileType.InnerHtml = txtFileField.PostedFile.ContentType;

        // convert bytes to Kbytes
        int size = txtFileField.PostedFile.ContentLength / 1024;
        FileSize.InnerHtml = (size.ToString() + " KB");
        uploadDetails.Visible = true;

        string strFileName = txtFileField.PostedFile.FileName;
        string c = Path.GetFileName(strFileName);

            // not sure if this path is correct. not working anyway
            txtFileField.PostedFile.SaveAs("~/" + c); 
            feedBack.InnerHtml = "File uploaded successfully.";
        catch (Exception exp)
            string message = "File did not upload, please try again";
            feedBack.InnerHtml = message + "\n" + exp.Message.ToString();
            uploadDetails.Visible= false;
Thanks for any help.

Fileupload problem



Can anybody help me out to clear the error. I am struggling from past few hours, my problem is this:

    private string SavePostedFiles(DevExpress.Web.ASPxUploadControl.UploadedFile uploadedFile)
        string ret = "";
        string fup;
        if (uploadedFile.IsValid)

MVC Fileupload problem


hey guys I'm trying to write a simple file upload page using ASP MVC2.

I've read some blog post so I started like this

 foreach (string file in Request.Files)
                HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                if (hpf.ContentLength > 0)
                    string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads")

FileUpload Problem


Hi, I am having problems storing the path where an image is saved.

I will like to sotre the path: _images\DemoImg.jpg  and not C:\inetpub\wwwroot\sweb\_images\DemoImg.jpg

With path saved as C:\inetpub\wwwroot\sweb\_images\DemoImg.jpg I cant read the image unless I change the path in the database.

Any help or suggestions will be very appreciated.


fileupload problem


below the codes works. it save files to database whenever user click on it.

but what i want is user uploaded a file to database, and when he uploads again, the uploaded file will replace the previous file leaving the database only have a single file all times. instead of keep on making a new row to store files.

help to correct my code...thanks all.....

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
        If FileExtensionIsApproved(fUpload.HasFile) Then
            Dim test = fUpload.PostedFile.FileName
            Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ToString)
            Dim da As New SqlDataAdapter("Select * From files", con)
            Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
            Dim ds As New DataSet()
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey
            Dim fs As New FileStream(test, FileMode.OpenOrCreate, FileAccess.Read)
            Dim MyData(fs.Length) As Byte
            fs.Read(MyData, 0, fs.Length)
            da.Fill(ds, "Mydata")
            Dim myRow As DataRow
            myRow = ds.Tables("Mydata").NewRow()

fileupload problem



I m uploading file to a directory inside my website root directory like this-


fileupload1.SaveAs(Server.MapPath(@"samples/" + new_sam_url.ToString()));

 I m getting exception-

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\WebSites\Elcomponics Sales-BD\samples\050841010_sd113201031833.pdf'.

Why so?

When i deployed my app on server and accessed it from client system. It is not throwing exception.What is the difference?

Still i want to confirm will it throw the same exception in case i deployed it to server and access

it from client

plz rep asap

thanx and regards

Problem to group radio button across gridview rows

In general no one can easily group or make a single selection from radio button list inside gridview rows. There are a lot of way to make a single or unique selection from list. Here i want to share how i can address this problem in the most easiest way. Googling the problem most of the cases i saw the grouping in horizontal way. Thats why i tried to group the radio buttons in vertical manner. Let i have a requirement like below:

Regrading Sharpoint 2010 problem and solutions

We can write your question and problem on this blogger.you get ans.use.

This sharpoint 2010 problem solving threads

Hi friend,

you can use this thread to solving problem and solutions.

Virtual Path Problem


 I get the following error on last line below (working on remote host): 'E:\web\sfcascom\ls_admin/uploads/images/001.JPG' is not a valid virtual path,

Note that the slashes go in different directions

I've tried a number of things but nothing seems to work. Thanks-


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Web.UI.WebControls

Imports System.Drawing.Imaging.ImageCodecInfo
Partial Class Protected_imageupload
    Inherits System.Web.UI.Page
    Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        ' Initialize variables
        Dim sSavePath As String
        Dim sThumbExtension As String
        Dim intThumbWidth As Integer
        Dim intThumbHeight As Integer
        Dim sFilename As String = ""
        ' Set constant values
        'sSavePath = "images/"
        sSavePath = Server.MapPath("~/") + "ls_admin/uploads/images/"

        sThumbExtension = "_thumb"
        intThumbWidth = 160
        intThumbHeight = 120

        ' If file field isn?t empty
        If FilUpload.PostedFile IsNot Nothing Then
            ' Check file size (mustn?t be 0)
            Dim myFile As Http

Server side validation of Fileupload control not working



I've tried this method in my code behind to try and validate that the Fileupload control has a file or not. I get the error message the the event "Server Validate" cannot be found. Can anyone tell why? Thanks.

Public Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

' Get file name

        Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload)

        Dim UploadFileName As String = uploadAvatar.PostedFile.FileName

        If UploadFileName = "" Then
            ' There is no file selected
            args.IsValid = False
            Dim Extension As String = UploadFileName.Substring(UploadFileName.L

Strange Photo upload problem


I'm working project it's live on shared hosting

we'er uploading photos to a file on the server everything works fine the photo is resized renamed and sent to the folder

the upload page returns the thumbnail and the full size photo it's there all the photos have to be approved by an admin

twice now after they have been approved they disapear I checked the folder they are not there could there be anywhere

on the server they could get hung up before they go into the folder I have it setup so when you delete the data base entry it deletes the photo from the folder othe than that you need to open the folder and delete the photo this has hapened twice now I tried to recreate it with no luck

thaks for your help in advance

ASP.Net Caching problem ??


I'm having a problem with an asp.net 3.0 application using a gridview to display data.  The problem seems to be that despite a brand new .selectCommand being sent to the sqlDataSource, the gridview starts displaying data from *someone else's* query.  For example, user A is logged in and will be working fine until a few page submissions later when the gridview data starts suddenly showing information that belongs to another user. 

This is my first asp.net application, though I've been working with classic asp and ADO for years so I'm used to sending a SQL string and getting back the results from that string.  Apparently there is a complex caching system which is interferring which I do not at all understand so at this point I just want to stop the server from caching any data whatsoever.  Is this possible?

Any and all help will be much appreciated!!

Could some one tell me whats the Problem with this String Manipulation ??? C#.net



I store some values from code behind to a label which is Hidden !

<asp:Label ID="lbl_Hidden" runat="server" Visible = "false"></asp:Label>

and at the page load event i retrieve the value of the label & assign it to a string !

stringvalue = lbl_Hidden.Text;

Now i dont know why this manipulation does'nt work !

I've a character 'A' in the string and i'm unable to replace it with a space !

stringvalue.Replace(A, " ");

Wot do u think abt it ????

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend