Skip to content

How to upload files from asp.net to remote server

shiva prasad

shiva prasad

Asked Apr 4, 2015, 4:01 AM EDT3 answers
Share
LinkedInX
Here is my code and iam getting the error as "the network path was not found"
 
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace Wind1
{
    public partial class Form1 : Form
    {
        string fileName = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }



        private void button1_Click_1(object sender, EventArgs e)
        {
            string path = "";
            OpenFileDialog fDialog = new OpenFileDialog();
            fDialog.Title = "Attach customer proposal document";
            fDialog.Filter = "Doc Files|*.doc|Docx File|*.docx|PDF doc|*.pdf";
            fDialog.InitialDirectory = @"C:\";
            if (fDialog.ShowDialog() == DialogResult.OK)
            {
                fileName = System.IO.Path.GetFileName(fDialog.FileName);
                path = Path.GetDirectoryName(fDialog.FileName);
                textBox1.Text = path + "\\" + fileName;

            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            try
            {
                WebClient client = new WebClient();

                NetworkCredential nc = new NetworkCredential("arcs360", "arcs");

                Uri addy = new Uri(@"\\10.255.1.147\Styles\" + fileName);

                client.Credentials = nc;
                byte[] arrReturn = client.UploadFile(addy,textBox1.Text);
                MessageBox.Show(arrReturn.ToString());

            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.Message);
            }
        }
    }
}

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Afzaal Ahmad Zeeshan
    0
    The error is the URI that you're using right now. 10.255.1.147\Styles\. Make sure that you are allowed to make requests to this IP address, otherwise use the domain name of your website. 

    Mostly, requests to the IP address based URIs are prevented, you can always consider using your own domain name. Or contact your web server admin for more infomration on this task. 
    0
  • shiva prasad
    0
    Iam using a godaddy server. It means I have to take permission from godaddy
    0
  • Afzaal Ahmad Zeeshan
    0
    Yes you should get help from them for setting this type of URIs for your project.
    0