WebClient

WebClient

Post by Vishnu Sunkar » Sat, 09 Mar 2002 03:16:03



I am trying to upload a file from Client Machine to IIS
server by using Uploadfile member in WebClient class.
This functionality is uploading from IIS server to other
resources but not from my client PC. (I am guesing I
misunderstood the documentation)

Is there any way that I can upload to my IIS server by
using dotnet framework?

Thank You
Vishnu

 
 
 

WebClient

Post by Robert E. Duke (Comforce/RhoTe » Sat, 09 Mar 2002 04:16:38


Hello Vishnu,

Your post is to the aspnet mobile news group.  Are you wanting to post from
a mobile device?  What client are you using?

Here is the info that I have available at this point:

Starting with "the way we used to do it":
http://support.microsoft.com/support/kb/articles/q317/3/10.asp.  

There are a few resources listed in this article.  What you will most
likely want to look into is the ASP.NET File Upload Control.  Search for
HtmlInputFile Control in the documention for ASP.NET.  Here is a
description:

Use the HtmlInputFile control to program against the HTML <input type=file>
element. You can use the HtmlInputFile control to easily design a page that
allows users to upload binary or text files from a browser to a directory
that you designate on your Web server. File upload is enabled in all HTML
3.2 and later Web browsers.

This should do the trick.  Please let me know if you have any questions.

Thank you,
Robert Duke
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

 
 
 

WebClient

Post by Robert E. Duke (Comforce/RhoTe » Sat, 09 Mar 2002 05:03:07


Hello Vishnu,

This is fantastic!  I used to support the file upload control.  It did not
bring joy to my life.  I just tried the HtmlInputFile control and it seems
great.  Keep in mind, you will have to be carefull of your security.  You
will have to allow write permissions for your users to the directory where
you save the files to.  If you allow anonymous users to upload files, you
will probably want to turn off execute permissions.  You have total control
over this though (which was not true of the file upload control).  Here is
the code that I used.  I modified the sample in the docs to work with the
code behind model.

WebForm1.aspx


AutoEventWireup="false" Inherits="FileUpload.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
        <HEAD>
                <title>WebForm1</title>
                <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
                <meta content="C#" name="CODE_LANGUAGE">
                <meta content="JavaScript" name="vs_defaultClientScript">
                <meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
        </HEAD>
        <body MS_POSITIONING="GridLayout">
                <form id="Form1" method="post" enctype="multipart/form-data"
runat="server">
                        <INPUT id="FileUploaded" style="Z-INDEX: 102; LEFT: 8px; POSITION:
absolute; TOP: 8px" type="file" runat=server>&nbsp;
                        <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 12px; POSITION:
absolute; TOP: 44px" runat="server" Text="Sumbit File"
Width="122px"></asp:Button>&nbsp;
                </form>
        </body>
</HTML>

WebForm1.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace FileUpload
{
        /// <summary>
        /// Summary description for WebForm1.
        /// </summary>
        public class WebForm1 : System.Web.UI.Page
        {
                protected System.Web.UI.WebControls.Button Button1;
                protected System.Web.UI.HtmlControls.HtmlInputFile FileUploaded;

                private void Page_Load(object sender, System.EventArgs e)
                {

                }

                #region Web Form Designer generated code
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }

                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                private void InitializeComponent()
                {    
                        this.Button1.Click += new System.EventHandler(this.Button1_Click);
                        this.Load += new System.EventHandler(this.Page_Load);

                }
                #endregion

                private void Button1_Click(object sender, System.EventArgs e)
                {
                        FileInfo fInfo = new FileInfo(FileUploaded.PostedFile.FileName);

FileUploaded.PostedFile.SaveAs("C:\\Inetpub\\wwwroot\\FileUpload\\UpLoadedFi
les\\" + fInfo.Name);
                }
        }

Quote:}

Enjoy,
Robert Duke
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

 
 
 

WebClient

Post by Vishnu Sunkar » Sat, 09 Mar 2002 06:47:38


Thank You Very much. I am sorry I posted in the mobile group. I am going
to give a try by using htmlinputfile.

Another question is there any way that I can read file on the client
machine? In other application we want to read and save data in SQL2000
server.

Thanks,
Vishnu

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

WebClient

Post by Robert E. Duke (Comforce/RhoTe » Sat, 09 Mar 2002 07:14:34


Hello Vishnu,

Quote:>> Another question is there any way that I can read file on the client

machine? In other application we want to read and save data in SQL2000
server.

You can't read a file that is located on the server from the client.  Is
that what you mean?  The server can send a link to the file to the browser.
 At the browser, the file is downloaded and either opened or saved.  The
point to understand here is the file is then on the client and any chages
will be to the client copy of the document.  You could then re-upload the
file.

I'm not really sure if this answers your question.  If not, please clarify
what you are asking and I'm more than happy to answer.

Thanks,
Robert Duke
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

 
 
 

WebClient

Post by Vishnu Sunkar » Sat, 09 Mar 2002 07:19:48


The file is on the client side, read it from the client and save it on
the SQL Server.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  _alt.0
< 1K Download
 
 
 

1. WebClient.UploadFile() and WebClient.DownloadFile()

How do I have checkpoint when using WebClient.UploadFile
() and WebClient.DownloadFile() so that when the upload
or download fails then I don't have to upload/download in
the beginning? (resume/suspend ability)

Or is there any other ways in doing this?

Thanks.

2. timeout after disconnection

3. Distribution of PD on CDROMs

4. WebClient.UploadFile()

5. Minnesota Power - Snail Pace

6. Screen Scarpping / WebClient

7. Media Player 7 and Windows ME question

8. ARE WE ONLINE? before doing webClient.downloadData() ???

9. System.Net.WebClient should remember cookies

10. WebClient not supported

11. Getting 401 Unauthorized error using WebClient UploadFile method

12. WebClient Problem: Can Anyone Give Me a Clue?