Solved

renaming file

Posted on 2011-02-11
1
237 Views
Last Modified: 2012-05-11
How can I rename an upload file? I wan to change the name to a GUID. Im using asp.net 4 and c#.

  string filepath = "C:\\Uploads";
        HttpFileCollection uploadedFiles = Request.Files;
        int i = 0;
        while (!(i == uploadedFiles.Count))
        {
            HttpPostedFile userPostedFile = uploadedFiles[i];
            try
            {
                if ((userPostedFile.ContentLength > 0))
                {
                    Label1.Text += "<u>File #" + (i + 1) + "</u><br>";
                    Label1.Text += "File Content Type: " + userPostedFile.ContentType + "<br>";
                    Label1.Text += "File Size: " + userPostedFile.ContentLength + "kb<br>";
                    Label1.Text += "File Name: " + userPostedFile.FileName + "<br>";
                    userPostedFile.SaveAs(filepath + "\\" + System.IO.Path.GetFileName(userPostedFile.FileName));
                    Label1.Text += "Location where saved: " + filepath + "\\" + System.IO.Path.GetFileName(userPostedFile.FileName) + "<p>";
                }
            }
            catch (Exception ex)
            {
                Label1.Text += "Error:<br>" + ex.Message;
            }
            i += 1;
        }

pls help

ayha

Open in new window

0
Comment
Question by:ayha1999
1 Comment
 
LVL 25

Accepted Solution

by:
SStory earned 250 total points
ID: 34870889
This will show you how. You can call it whatever you like.

http://www.codeproject.com/KB/aspnet/fileupload.aspx

I assume you know how to get the GUID.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now