Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to have a little code in VB.net to upload a file AND some information (like the name and a login-code of these person). So it will have to perform like these html-form.

XML
<FORM ACTION=".../file.php">
name: <INPUT NAME="nickname"><BR>
code: <INPUT NAME="code"><BR>
file: <input name="userfile" type="file" />
<INPUT TYPE=SUBMIT>
</FORM>


I have already found the code below, but I don't know how to implement the nickname and the login-code...

Thanks for your help,

wimvr

______________

VB
Dim filepath As String = TextboxSelectedFile.Text
Dim url As String = "www.mysite.be/file.php"

Dim boundary As String = IO.Path.GetRandomFileName
Dim header As New System.Text.StringBuilder()
header.AppendLine("--" & boundary)
header.Append("Content-Disposition: form-data; name=""userfile"";")
header.AppendFormat("filename=""{0}""", IO.Path.GetFileName(filepath))
header.AppendLine()
header.AppendLine("Content-Type: application/octet-stream")
header.AppendLine()

Dim headerbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(header.ToString)
Dim endboundarybytes() As Byte = System.Text.Encoding.ASCII.GetBytes(vbNewLine & "--" & boundary & "--" & vbNewLine)

Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create(url)
req.ContentType = "multipart/form-data; boundary=" & boundary
req.ContentLength = headerbytes.Length + New IO.FileInfo(filepath).Length + endboundarybytes.Length
req.Method = "POST"

Dim s As IO.Stream = req.GetRequestStream
s.Write(headerbytes, 0, headerbytes.Length)
Dim filebytes() As Byte = My.Computer.FileSystem.ReadAllBytes(filepath)
s.Write(filebytes, 0, filebytes.Length)
s.Write(endboundarybytes, 0, endboundarybytes.Length)
s.Close()

'Get the responds of these request
Dim resp As Net.HttpWebResponse = req.GetResponse()
Dim sresp As IO.Stream = resp.GetResponseStream()
Dim bytes(80000) As Byte
sresp.Read(bytes, 0, 80000)
Textbox1.Text = System.Text.Encoding.ASCII.GetChars(bytes)
Posted

Check this one using multpart/form-data
Link
 
Share this answer
 
Comments
wimvr 7-Jul-11 14:38pm    
IS there also a place where I can learn how I must create a server request? (Only how you must write the header and the boundary?)
on php put this script

file.php
PHP
<?php 
 $target = "cb_upload/"; 
 $target = $target . basename( $_FILES['userfile']['name']) ; 
 $ok=1; 
 if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target)) 
 {
 echo "The file ". basename( $_FILES['userfile']['name']). " has been uploaded";
 } 
 else {
 echo "Sorry, there was a problem uploading your file.";
 }
 ?> 

cb_upload is your root folder where the file want to be placed
 
Share this answer
 
XML
?php
error_reporting(0);
session_start();
if(isset($_SESSION['adminusername'])){
        echo "<span class='message'>Welcome  <b>".$_SESSION['adminusername']."</b></span>";
    }
    else{
        header("Location:index.php");
        }
?>
<?php if(isset($_POST['logout'])){session_destroy(); header("Location:index.php");}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>College Information Management</title>
<link rel="stylesheet" type="text/css" href="bsm.css"/>
</head>
<body>
<div id="container">
<div class="header">
<img style="margin:10px 2px 2px 10px;float:left;" height="108" width="190" src="images/college.gif" alt="OES"/><h3 class="headtext"> &nbsp;College Information Mananagement</h3><h4 style="color:#ffffff;text-align:center;margin:0 0 5px 5px;"><i></i></h4>
</div>
<div class="menubar">
 <ul id="menu">
<form action="" method="post">
<li><input type="submit" value="Logout" name="logout" class="subbtn"></li>
</form>
 </ul>
 </div>
  <div class="page">
  <div class="pmsg" style="text-align:center;">Admin Home</div>
   <div class="adminhme" align="center">



<ul class="nav"><li><a href="managecategory.php?condition=1">Manage Category</a></li><li><a href="manageuniversity.php?condition=1">Manage University</a></li><li><a href="managecourse.php?condition=1">Manage Course</a></li><li><a href="manageclginfo.php?condition=1">Manage College information</a></li><li><a href="manageclgcourse.php?condition=1">Manage College Course</a></li></ul>
</div>

</div>
</body>
</html>
<?php error_reporting(0); ?>
<script type="application/javascript" src="js/gusthome.js">
</script>
</head>
<body>

 <div class="page">
<div class="pmsg" style="text-align:center;">Search here</div>
 <form action="adminhome.php?searchresult" method="POST">
    <table align="center" cellpadding="20" cellspacing="20" style="text-align:left;margin-left:15em">
     <tr><td>Search By</td><td><select id="optnc" name="optncateg">
    <option value="select">--Select--</option>
    <option value="category">Category</option>
     <option value="college">CollegeName</option>
    <option value="university">University</option>
    <option value="course">Course</option>
    </select></td>
    <td><input type="text" name="searchField" id="searchField" /></td>
    <td><input type="submit" name="search" id="search" value="Search" class="subbtn" onclick="return val();"/></td></tr>
     </table>
    </form>
    <?php
    if(isset($_GET['searchresult'])){
    include("dbconnection.php");
if(isset($_POST['search'])){
    $optncateg = $_POST['optncateg'];
    $searchField = $_POST['searchField'];
if($optncateg == 'category'){
            $data=mysql_query("SELECT `id` FROM  `category` WHERE `category` LIKE '$searchField%'");
$res = mysql_num_rows($data);
if($res > 0){
    $result = mysql_fetch_row($data);
$data1=mysql_query("SELECT * FROM  `college_information` WHERE `category_id`='$result[0]'");
    echo "<div class='message' align='center'>category search results</div>";
    echo "<table cellpadding='30' cellspacing='10' class='datatable'>";

        echo "<tr><th>College</th><th>University</th><th>Address</th><th>Phone No</th><th>Fax</th><th>Email</th><th>Website</th><th>Ested Year</th><th>View Course</th></tr>";

        while ($result1 = mysql_fetch_row($data1)){
            $data2=mysql_query("SELECT `university` FROM  `university_master` WHERE `id`='$result1[2]'");
$result2 = mysql_fetch_row($data2);
    echo "<tr><td>$result1[1]</td><td>$result2[0]</td><td>$result1[4]</td><td>$result1[5]</td><td>$result1[6]</td><td>$result1[7]</td><td>$result1[8]</td><td>$result1[11]</td><td><a href='adminhome.php?viewcourses=$result1[1]'>View Courses</a></td></tr>";
            }
         echo "</table>";
    }
else{
    echo "<span class='message'>No Result associated with your search</span>";
    }
    }
if($optncateg == 'college'){
            $data=mysql_query("SELECT * FROM  `college_information` WHERE `name` LIKE '$searchField%'");
$res = mysql_num_rows($data);
if($res > 0){

    echo "<div class='message' align='center'>college search results</div>";
    echo "<table cellpadding='30' cellspacing='10' class='datatable'>";

        echo "<tr><th>College</th><th>University</th><th>Category</th><th>Address</th><th>Phone No</th><th>Fax</th><th>Email</th><th>Website</th><th>Ested Year</th><th>View Course</th></tr>";
        while ($result = mysql_fetch_row($data)){
$data1=mysql_query("SELECT `university` FROM  `university_master` WHERE `id`='$result[1]'");
$result1=mysql_fetch_row($data1);
$data2=mysql_query("SELECT `category` FROM  `category` WHERE `id`='$result[2]'");
$result2=mysql_fetch_row($data2);
    echo "<tr><td>$result[1]</td><td>$result1[0]</td><td>$result2[0]</td><td>$result[4]</td><td>$result[5]</td><td>$result[6]</td><td>$result[7]</td><td>$result[8]</td><td>$result[11]</td><td><a href='adminhome.php?viewcourses=$result[1]'>View Courses</a></td></tr>";
            }
         echo "</table>";
    }
else{
    echo "<span class='message'>No Result associated with your search</span>";
    }
    }
if($optncateg == 'university'){
            $data=mysql_query("SELECT `id` FROM  `university_master` WHERE `university` LIKE '$searchField%'");
$res = mysql_num_rows($data);
if($res > 0){
    $result = mysql_fetch_row($data);
$data1=mysql_query("SELECT * FROM  `college_information` WHERE `university_id`='$result[0]'");
    echo "<div class='message' align='center'>university search results</div>";
    echo "<table cellpadding='30' cellspacing='10' class='datatable'>";

        echo "<tr><th>College</th><th>Category</th><th>Address</th><th>Phone No</th><th>Fax</th><th>Email</th><th>Website</th><th>Ested Year</th><th>View Course</th></tr>";

        while ($result1 = mysql_fetch_row($data1)){
            $data2=mysql_query("SELECT `category` FROM `category` WHERE `id`='$result1[3]'");
$result2 = mysql_fetch_row($data2);
    echo "<tr><td>$result1[1]</td><td>$result2[0]</td><td>$result1[4]</td><td>$result1[5]</td><td>$result1[6]</td><td>$result1[7]</td><td>$result1[8]</td><td>$result1[11]</td><td><a href='adminhome.php?viewcourses=$result1[1]'>View Courses</a></td></tr>";
            }
         echo "</table>";
    }
else{
    echo "<span class='message'>No Result associated with your search</span>";
    }
    }

    if($optncateg == 'course'){
            $data=mysql_query("SELECT `id` FROM `course_master` WHERE `course` LIKE '$searchField%'");
$res = mysql_num_rows($data);
if($res > 0){
    $result = mysql_fetch_row($data);
$data1=mysql_query("SELECT `college_id` FROM `college_course_master` WHERE `course_id`='$result[0]'");
    echo "<div class='message' align='center'>course search results</div>";
    echo "<table cellpadding='30' cellspacing='10' class='datatable'>";
        echo "<tr><th>College</th><th>Address</th><th>Phone No</th><th>Fax</th><th>Email</th><th>Website</th><th>Ested Year</th></tr>";
        while ($result1 = mysql_fetch_row($data1)){
            $data2=mysql_query("SELECT * FROM  `college_information` WHERE `id`='$result1[0]'");
$result2 = mysql_fetch_row($data2);
    echo "<tr><td>$result2[1]</td><td>$result2[4]</td><td>$result2[5]</td><td>$result2[6]</td><td>$result2[7]</td><td>$result2[8]</td><td>$result2[11]</td></tr>";
            }
         echo "</table>";
    }
else{
    echo "<span class='message'>No Result associated with your search</span>";
    }
    }
    }
    }
    ?>
    <?php
    if(isset($_GET['viewcourses'])){
        $clgname=$_GET['viewcourses'];
        include("dbconnection.php");

    $datas=mysql_query("SELECT `id` FROM `college_information` WHERE `name`='$clgname'");
    $reslt=mysql_fetch_row($datas);
    $datas1=mysql_query("SELECT * FROM `college_course_master` WHERE `college_id`='$reslt[0]'");
    echo "<table cellpadding='30' cellspacing='10' class='datatable'>";
        echo "<tr><th>College</th><th>Courses</th><th>Total Seats</th></tr>";
    while($reslt1=mysql_fetch_row($datas1)){
    $datas2=mysql_query("SELECT `course` FROM `course_master` WHERE `id`='$reslt1[2]'");
    $reslt2=mysql_fetch_row($datas2);
    echo "<tr><td>$clgname</td><td>$reslt2[0]</td><td>$reslt1[3]</td></tr>";
        }
             echo "</table>";
        }
    ?>
<?php
if(isset($_GET['all'])){

    //connect to the database
    include_once ('db.php');
    //get the function
    include_once ('function.php');

        $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
        $limit = 5;
        $startpoint = ($page * $limit) - $limit;

        //to make pagination
        $statement = "`college_information`";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link href="pagination.css" rel="stylesheet" type="text/css" />
    <link href="B_blue.css" rel="stylesheet" type="text/css" />

</head>

<body>

<table cellpadding='30' cellspacing='10' class='datatable'>
<tr><th>College</th><th>University</th><th>Category</th><th>Address</th><th>Phone No</th><th>Fax</th><th>Email</th><th>Website</th><th>Ested Year</th><th>View Course</th></tr>
        <?php
            //show records
            $query = mysql_query("SELECT * FROM {$statement} LIMIT {$startpoint} , {$limit}");
            $co=mysql_num_rows($query);
if($co>0){
            while ($row = mysql_fetch_row($query)) {
    $qry1=mysql_query("SELECT `university` FROM `university_master` WHERE `id`='$row[2]'");
    $row1=mysql_fetch_row($qry1);
    $qry2=mysql_query("SELECT `category` FROM `category` WHERE `id`='$row[3]'");
    $row2=mysql_fetch_row($qry2);
            echo "<tr><td>$row[1]</td><td>$row1[0]</td><td>$row2[0]</td><td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>$row[7]</td><td>$row[8]</td><td>$row[11]</td><td><a href='adminhome.php?viewcourses=$row[1]'>View Courses</a></td></tr>";?>
        <?php
            }
}
else{
    echo "<span class='message'>Currently no Results</span>";
    }
        ?>
</table>

<?php
    echo pagination($statement,$limit,$page);

}
?>
        </div>
        <div id="footer">
          <p style="font-size:70%;color:#ffffff;">Copyright</b><br/></p>College Information Mananagement<p>
      </div>
            </div>

</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900