copy file exchange code from sample code