. NET to upload a file across the server to download the tutorial

Source: Internet
Author: User
Tags datetime

Environment description

Two server servers are a, server is B, Server B is file server

Implementation methods

1. Create user docshareuser on A and B, keep the username and password consistent

2, b server Set up the Attachment folder attachments share, add user Docshareuser and set read and write permissions

3, in a Run the box input "\\IP\Attachments", enter the username password test whether sharing success, sharing unsuccessful please check the network and configuration problems

4, modify the Aweb.config file attachment path node value

<add key= "key value" value= "\\IP address \attachments"/>

5, under the <system.web> node to add the following configuration, user name password and create a shared account to maintain the same

<identity impersonate= "true" Username= "Docshareuser" password= "password"/>

Test Upload success! Download times wrong:

Because the download method is as follows:

Context. Response.appendheader ("Content-length", filesize.tostring ());
Context. Response.CacheControl = HttpCacheability.Public.ToString ();
Context. Response.Cache.AppendCacheExtension ("max-age=" + 365 * 24 * 60 * 60);
Context. Response.Cache.SetExpires (DateTime.Now.AddYears (1));
Context. Response.appendheader ("ETag", "never_modify");
Context. Response.Cache.SetETag ("never_modify");
Context. Response.Cache.SetLastModified (DateTime.Now.AddMinutes (-1));
Context. Response.TransmitFile (FilePath);

Modify the Download mode:

FileStream FS =newfilestream (FilePath, FileMode.Open);
    byte[] bytes =newbyte[(int) fs. Length];
    fs. Read (bytes, 0, bytes. Length);
    fs. Close ();
    response.contenttype = "Application/octet-stream";
    //notifies the browser to download the file instead of opening the
    respons E.addheader ("Content-disposition", "attachment filename=" + httputility.urlencode (filename, SYSTEM.TEXT.ENCODING.UTF8));
    context. Response.BinaryWrite (bytes);
    context. Response.Flush ();
    context. Response.End ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.