مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

koroshpa

عضویت از 1392/06/05

آدرس یک فولدر در پوشه برنامه !

  • شنبه 18 دی 1395
  • 10:40
تشکر میکنم

سلام 

من  می خوام بگم ی فایل انتخاب شده در فولدری در پوشه برنامه کپی شود .

این آدرس فولدر در پوشه برنامه چجوری باید داد ؟

الان فولدر من اسمش ali هست در کنار فایل های اصلی در پوشه Debug هست .

متشکر

پاسخ های این پرسش

تعداد پاسخ ها : 5 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • شنبه 18 دی 1395
  • 10:48

با استفاده از Application.StatupPath میتونید مسیر اجرا را بدست بیارید و بعد بجسبانید به فولدر ali و بعد دستور کپی را بنویسید

    // Simple synchronous file copy operations with no user interface.
    // To run this sample, first create the following directories and files:
    // C:\Users\Public\TestFolder
    // C:\Users\Public\TestFolder\test.txt
    // C:\Users\Public\TestFolder\SubDir\test.txt
    public class SimpleFileCopy
    {
        static void Main()
        {
            string fileName = "test.txt";
            string sourcePath = @"C:\Users\Public\TestFolder";
            string targetPath =  @"C:\Users\Public\TestFolder\SubDir";

            // Use Path class to manipulate file and directory paths.
            string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
            string destFile = System.IO.Path.Combine(targetPath, fileName);

            // To copy a folder's contents to a new location:
            // Create a new target folder, if necessary.
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            // To copy a file to another location and 
            // overwrite the destination file if it already exists.
            System.IO.File.Copy(sourceFile, destFile, true);
            
            // To copy all the files in one directory to another directory.
            // Get the files in the source folder. (To recursively iterate through
            // all subfolders under the current directory, see
            // "How to: Iterate Through a Directory Tree.")
            // Note: Check for target path was performed previously
            //       in this code example.
            if (System.IO.Directory.Exists(sourcePath))
            {
                string[] files = System.IO.Directory.GetFiles(sourcePath);

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    // Use static Path methods to extract only the file name from the path.
                    fileName = System.IO.Path.GetFileName(s);
                    destFile = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(s, destFile, true);
                }
            }
            else
            {
                Console.WriteLine("Source path does not exist!");
            }

            // Keep console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }

کاربر سایت

koroshpa

عضویت از 1392/06/05

  • شنبه 18 دی 1395
  • 20:11

من فقط یک آدرس میخوام که فایل در اونجا کپی بشه یا move بشه اون آدرس هم در پوشه خود برنامه هست !

در asp آدرس رو با قرار دادن یک ~  میدادیم که مثلا در روت فولدر هست !

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • یکشنبه 19 دی 1395
  • 09:22

باید ادرس مطلق یا فیزیکی باشد پس از Server,MapPath استفاده کنید

کاربر سایت

koroshpa

عضویت از 1392/06/05

  • یکشنبه 19 دی 1395
  • 18:06

تو برنامه ویندوزی از servermapPath مگه میشه استفاده کرد؟

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • یکشنبه 19 دی 1395
  • 18:34

خیر

از Application.StartupPath استفاده کنید

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)